7 Module implementing the UI Previewer main window. |
7 Module implementing the UI Previewer main window. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import qVersion, QDir, QFileInfo, QEvent, QSize, Qt |
12 from PyQt5.QtCore import QDir, QFileInfo, QEvent, QSize, Qt |
13 from PyQt5.QtGui import QCursor, QKeySequence, QPixmap, QImageWriter, QPainter |
13 from PyQt5.QtGui import QCursor, QKeySequence, QPixmap, QImageWriter, QPainter |
14 from PyQt5.QtWidgets import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, \ |
14 from PyQt5.QtWidgets import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, \ |
15 QWhatsThis, QDialog, QScrollArea, qApp, QApplication, QStyleFactory, \ |
15 QWhatsThis, QDialog, QScrollArea, qApp, QApplication, QStyleFactory, \ |
16 QFrame, QMainWindow, QComboBox, QVBoxLayout, QAction, QLabel |
16 QFrame, QMainWindow, QComboBox, QVBoxLayout, QAction, QLabel |
17 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog |
17 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog |
472 ext = QFileInfo(fname).suffix().upper() |
473 ext = QFileInfo(fname).suffix().upper() |
473 if not ext: |
474 if not ext: |
474 ext = defaultExt |
475 ext = defaultExt |
475 fname.append(".{0}".format(defaultExt.lower())) |
476 fname.append(".{0}".format(defaultExt.lower())) |
476 |
477 |
477 if qVersion() >= "5.0.0": |
478 if qVersionTuple() >= (5, 0, 0): |
478 pix = self.mainWidget.grab() |
479 pix = self.mainWidget.grab() |
479 else: |
480 else: |
480 pix = QPixmap.grabWidget(self.mainWidget) |
481 pix = QPixmap.grabWidget(self.mainWidget) |
481 self.__updateChildren(self.lastStyle) |
482 self.__updateChildren(self.lastStyle) |
482 if not pix.save(fname, str(ext)): |
483 if not pix.save(fname, str(ext)): |
497 self.tr("Save Image"), |
498 self.tr("Save Image"), |
498 self.tr("""There is no UI file loaded.""")) |
499 self.tr("""There is no UI file loaded.""")) |
499 return |
500 return |
500 |
501 |
501 cb = QApplication.clipboard() |
502 cb = QApplication.clipboard() |
502 if qVersion() >= "5.0.0": |
503 if qVersionTuple() >= (5, 0, 0): |
503 cb.setPixmap(self.mainWidget.grab()) |
504 cb.setPixmap(self.mainWidget.grab()) |
504 else: |
505 else: |
505 cb.setPixmap(QPixmap.grabWidget(self.mainWidget)) |
506 cb.setPixmap(QPixmap.grabWidget(self.mainWidget)) |
506 self.__updateChildren(self.lastStyle) |
507 self.__updateChildren(self.lastStyle) |
507 |
508 |
595 height = printer.height() - marginY * 3 |
596 height = printer.height() - marginY * 3 |
596 else: |
597 else: |
597 marginX *= 2 |
598 marginX *= 2 |
598 width = printer.width() - marginX * 2 |
599 width = printer.width() - marginX * 2 |
599 height = printer.height() - marginY * 2 |
600 height = printer.height() - marginY * 2 |
600 if qVersion() >= "5.0.0": |
601 if qVersionTuple() >= (5, 0, 0): |
601 img = self.mainWidget.grab().toImage() |
602 img = self.mainWidget.grab().toImage() |
602 else: |
603 else: |
603 img = QPixmap.grabWidget(self.mainWidget).toImage() |
604 img = QPixmap.grabWidget(self.mainWidget).toImage() |
604 self.__updateChildren(self.lastStyle) |
605 self.__updateChildren(self.lastStyle) |
605 p.drawImage(marginX, marginY, |
606 p.drawImage(marginX, marginY, |