Package mcbase :: Package libs :: Package reportviewer :: Module viewerwidget
[hide private]
[frames] | no frames]

Source Code for Module mcbase.libs.reportviewer.viewerwidget

  1  # -*- coding: utf-8 -*- 
  2   
  3  ########################################################################## 
  4  # viewerwidget.py 
  5  # 
  6  # Rapor Gösterim Nesnesi 
  7  # 
  8  # (C) 2007 Likya Yazılım ve Bilişim Hizmetleri Ltd. Şti. 
  9  ########################################################################## 
 10   
 11  from PyQt4.QtCore import * 
 12  from PyQt4.QtGui import * 
 13   
 14  from viewer import Viewer 
 15  from toolbar import ToolBar 
 16   
 17  from constants import Constants 
 18   
19 -class ViewerWidget(QWidget):
20
21 - def __init__(self, parent):
22 QWidget.__init__(self, parent) 23 24 # Rapor Görünümü 25 self._viewer = Viewer(self) 26 self._viewer.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) 27 28 # Tool Bar 29 self._toolbar = ToolBar(self) 30 self._toolbar.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)) 31 32 # Status Bar 33 self._statusBar = QStatusBar(self) 34 self._statusBar.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)) 35 self._statusBar.setSizeGripEnabled(False) 36 37 self._pageSource = None 38 39 self.layoutItems() 40 41 # Sinyaller ve ayarlar. 42 self.initItems()
43
44 - def initItems(self):
45 ''' 46 Sinyaller ve ayarlar 47 ''' 48 self.connect(self._toolbar, SIGNAL('resetPages()'), self, SIGNAL('resetPages()')) 49 self.connect(self._toolbar, SIGNAL('print()'), self, SIGNAL('print()')) 50 self.connect(self._toolbar, SIGNAL('setZoom(float)'), self.setZoom) 51 self.connect(self._toolbar, SIGNAL('adjustZoomForPageWidth()'), self.adjustZoomForPageWidth) 52 self.connect(self._toolbar, SIGNAL('adjustZoomForPageHeight()'), self.adjustZoomForPageHeight) 53 self.connect(self._toolbar, SIGNAL('pageOrientationChanged()'), self.pageOrientationChanged) 54 self.connect(self._toolbar, SIGNAL('gotoPage(int)'), self._viewer.gotoPage) 55 self.connect(self._toolbar, SIGNAL('paperTypeChanged(PyQt_PyObject)'), self.paperTypeChanged) 56 self.connect(self._viewer, SIGNAL('setPageNumberText(int)'), self._toolbar.setPageNumberText)
57
58 - def setZoom(self, newRatio):
59 ''' 60 Yeni zoom oranını yansıtıyoruz. 61 ''' 62 self._pageSource.setZoom(newRatio) 63 self.emit(SIGNAL('resetPages()'))
64
65 - def adjustZoomForPageWidth(self):
66 ''' 67 Sayfa genişliğine göre zoom yapar. 68 ''' 69 pageWidth = self._pageSource.pageWidth(False) + Viewer.MARGIN 70 71 zoomRatio = Viewer.WIDTH / float(pageWidth) 72 zoomRatio = min(abs(zoomRatio), 4) 73 zoomRatio = max(abs(zoomRatio), 0.1) 74 75 self._toolbar.setZoom(zoomRatio)
76
77 - def adjustZoomForPageHeight(self):
78 ''' 79 Sayfa yüksekliğine göre zoom yapar. 80 ''' 81 pageHeight = self._pageSource.pageHeight(False) + Viewer.MARGIN 82 83 zoomRatio = Viewer.HEIGHT / float(pageHeight) 84 zoomRatio = min(abs(zoomRatio), 4) 85 zoomRatio = max(abs(zoomRatio), 0.1) 86 87 self._toolbar.setZoom(zoomRatio)
88
89 - def setPageSource(self, pageSource):
90 ''' 91 Sayfa kaynağını gösterim ekranına belirtir. 92 ''' 93 self._pageSource = pageSource
94
95 - def viewer(self):
96 ''' 97 Sayfaların gösterildiği ekranı döndürür. 98 ''' 99 return self._viewer
100
101 - def toolbar(self):
102 ''' 103 ToolBar nesnesini belirtir. 104 ''' 105 return self._toolbar
106
107 - def clearPages(self):
108 ''' 109 Tüm görüntüyü siler. 110 ''' 111 self._viewer.clearPages()
112
113 - def addPages(self):
114 ''' 115 Gösterim ekranına bir sayfa ekler. 116 ''' 117 self._viewer.addPages(self._pageSource)
118
119 - def layoutItems(self):
120 ''' 121 Görünüm ekranındaki nesneleri dizer. 122 ''' 123 layout = QVBoxLayout(self) 124 125 layout.setSpacing(3) 126 layout.setMargin(0) 127 128 layout.addWidget(self._toolbar) 129 layout.addWidget(self._viewer) 130 layout.addWidget(self._statusBar)
131
132 - def layoutPages(self):
133 ''' 134 Rapor sayfalarını ilgili layout'a göre düzgünce yerleştirir. 135 ''' 136 self._viewer.layoutPages()
137
138 - def adjustContentsSize(self):
139 ''' 140 Nesnelerin kapladığı alana göre scroll barları yeniden ayarlar. 141 ''' 142 self._viewer.adjustContentsSize()
143
144 - def getPageSizes(self, pageOrientation=Constants.ORIENTATION_PORTRAIT):
145 ''' 146 Kağıt türüne göre uygun sayfa boylarını verir. 147 ''' 148 paperType = self._toolbar.paperType() 149 150 width = None 151 height = None 152 153 if paperType != 'DESIGN' and paperType in Constants.PAPER_SIZES: 154 paperWidth, paperHeight = Constants.PAPER_SIZES[paperType] 155 sideRatio = float(paperWidth) / float(paperHeight) 156 157 pageWidth = None 158 pageHeight = None 159 160 if pageOrientation == Constants.ORIENTATION_PORTRAIT: 161 pageWidth = self._pageSource.pageWidth(False) 162 pageHeight = self._pageSource.pageHeight(False) 163 164 else: 165 pageHeight = self._pageSource.pageWidth(False) 166 pageWidth = self._pageSource.pageHeight(False) 167 168 widthRatiod = (pageWidth, pageWidth / sideRatio) 169 heightRatiod = (pageHeight * sideRatio, pageHeight) 170 171 width, height = max(widthRatiod, heightRatiod) 172 173 return width, height
174
175 - def pageOrientationChanged(self):
176 ''' 177 Sayfa yönü değiştiği zaman çalışır. 178 ''' 179 pageOrientation = self._toolbar.pageOrientation() 180 181 self._pageSource.setAbsoluteLengths(None, None) 182 183 if pageOrientation == Constants.ORIENTATION_LANDSCAPE: 184 paperType = self._pageSource.paperType() 185 self._toolbar.setPaperType(paperType) 186 187 width, height = self.getPageSizes(pageOrientation) 188 self._pageSource.setAbsoluteLengths(width, height) 189 190 self._pageSource.setPageOrientation(pageOrientation) 191 192 if pageOrientation == Constants.ORIENTATION_LANDSCAPE: 193 self.adjustZoomForPageHeight() 194 195 else: 196 self.emit(SIGNAL('resetPages()'))
197
198 - def paperTypeChanged(self, paperType):
199 ''' 200 Sayfa boyutu değiştiği zaman çalışır. 201 ''' 202 pageOrientation = Constants.ORIENTATION_PORTRAIT 203 204 self._pageSource.setAbsoluteLengths(None, None) 205 206 if paperType != 'DESIGN' and paperType in Constants.PAPER_SIZES: 207 # Eğer yatay baskı ise, görünümü yatay yapıyoruz. 208 pageOrientation = self._pageSource.preferredPageOrientation() 209 210 width, height = self.getPageSizes(pageOrientation) 211 self._pageSource.setAbsoluteLengths(width, height) 212 213 else: 214 self._pageSource.setAbsoluteLengths(None, None) 215 216 self._pageSource.setPageOrientation(pageOrientation) 217 self._toolbar.setPageOrientation(pageOrientation) 218 219 self.emit(SIGNAL('resetPages()'))
220
221 - def event(self, e):
222 # Status eventlerini status bar'da gösterir. 223 if e.type() == QEvent.StatusTip: 224 self._statusBar.showMessage(e.tip()) 225 226 return QWidget.event(self, e)
227