44 #include <private/qprinter_p.h> 45 #include "private/qdialog_p.h" 47 #include <QtGui/qaction.h> 48 #include <QtGui/qboxlayout.h> 49 #include <QtGui/qcombobox.h> 50 #include <QtGui/qlabel.h> 51 #include <QtGui/qlineedit.h> 52 #include <QtGui/qpagesetupdialog.h> 53 #include <QtGui/qprinter.h> 54 #include <QtGui/qstyle.h> 55 #include <QtGui/qtoolbutton.h> 56 #include <QtGui/qvalidator.h> 57 #include <QtGui/qfiledialog.h> 58 #include <QtGui/qmainwindow.h> 59 #include <QtGui/qtoolbar.h> 60 #include <QtGui/qformlayout.h> 61 #include <QtCore/QCoreApplication> 65 #ifndef QT_NO_PRINTPREVIEWDIALOG 80 ZoomFactorValidator(
QObject* parent)
87 bool replacePercent =
false;
90 replacePercent =
true;
95 const int num_size = 4;
96 if (state == Intermediate) {
98 if ((i == -1 && input.
size() > num_size)
99 || (i != -1 && i > num_size))
114 connect(
this,
SIGNAL(returnPressed()),
SLOT(handleReturnPressed()));
126 if (isModified() && !hasAcceptableInput())
132 void handleReturnPressed()
147 : printDialog(0), ownPrinter(false),
148 initialized(false) {}
154 void _q_navigate(
QAction *action);
155 void _q_setMode(
QAction *action);
156 void _q_pageNumEdited();
159 void _q_previewChanged();
160 void _q_zoomFactorChanged();
163 void populateScene();
166 void updateNavActions();
167 void setFitting(
bool on);
169 void updatePageNumLabel();
170 void updateZoomFactor();
210 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) 234 pageNumEdit =
new LineEdit;
237 pageNumLabel =
new QLabel;
242 zoomFactor->setMinimumContentsLength(7);
244 LineEdit *zoomEditor =
new LineEdit;
245 zoomEditor->setValidator(
new ZoomFactorValidator(1, 1000, 1, zoomEditor));
246 zoomFactor->setLineEdit(zoomEditor);
247 static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
248 for (
int i = 0; i < int(
sizeof(factorsX2) /
sizeof(factorsX2[0])); ++i)
251 q,
SLOT(_q_zoomFactorChanged()));
253 q,
SLOT(_q_zoomFactorChanged()));
255 QPrintPreviewMainWindow *mw =
new QPrintPreviewMainWindow(q);
279 QSize pageNumEditSize, pageNumLabelSize;
280 pageNumEditSize = pageNumEdit->minimumSizeHint();
281 pageNumLabelSize = pageNumLabel->minimumSizeHint();
282 pageNumEdit->resize(pageNumEditSize);
283 pageNumLabel->resize(pageNumLabelSize);
306 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) 322 mw->addToolBar(toolbar);
323 mw->setCentralWidget(preview);
331 q->setLayout(topLayout);
334 if (!printer->docName().isEmpty())
336 q->setWindowTitle(caption);
338 if (!printer->isValid()
339 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) 343 pageSetupAction->setEnabled(
false);
349 QLatin1String imagePrefix(
":/trolltech/dialogs/qprintpreviewdialog/images/");
362 navGroup->setExclusive(
false);
377 fitWidthAction->setObjectName(
QLatin1String(
"fitWidthAction"));
378 fitPageAction->setObjectName(
QLatin1String(
"fitPageAction"));
379 fitWidthAction->setCheckable(
true);
380 fitPageAction->setCheckable(
true);
396 portraitAction->setCheckable(
true);
397 landscapeAction->setCheckable(
true);
411 singleModeAction->setObjectName(
QLatin1String(
"singleModeAction"));
412 facingModeAction->setObjectName(
QLatin1String(
"facingModeAction"));
413 overviewModeAction->setObjectName(
QLatin1String(
"overviewModeAction"));
415 singleModeAction->setCheckable(
true);
416 facingModeAction->setCheckable(
true);
417 overviewModeAction->setCheckable(
true);
428 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) 434 fitPageAction->setChecked(
true);
435 singleModeAction->setChecked(
true);
437 portraitAction->setChecked(
true);
439 landscapeAction->setChecked(
true);
445 return (fitGroup->isExclusive()
446 && (fitWidthAction->isChecked() || fitPageAction->isChecked()));
452 if (isFitting() == on)
454 fitGroup->setExclusive(on);
456 QAction* action = fitWidthAction->
isChecked() ? fitWidthAction : fitPageAction;
458 if (fitGroup->checkedAction() != action) {
460 fitGroup->removeAction(action);
461 fitGroup->addAction(action);
464 fitWidthAction->setChecked(
false);
465 fitPageAction->setChecked(
false);
471 int curPage = preview->currentPage();
472 int numPages = preview->pageCount();
473 nextPageAction->setEnabled(curPage < numPages);
474 prevPageAction->setEnabled(curPage > 1);
475 firstPageAction->setEnabled(curPage > 1);
476 lastPageAction->setEnabled(curPage < numPages);
484 int numPages = preview->pageCount();
487 int cyphersWidth = q->fontMetrics().width(
QString().fill(
QLatin1Char(
'8'), maxChars));
488 int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
489 pageNumEdit->setMinimumWidth(maxWidth);
490 pageNumEdit->setMaximumWidth(maxWidth);
491 pageNumEdit->setValidator(
new QIntValidator(1, numPages, pageNumEdit));
497 zoomFactor->lineEdit()->setText(
QString().sprintf(
"%.1f%%", preview->zoomFactor()*100));
503 if (action == fitPageAction)
504 preview->fitInView();
506 preview->fitToWidth();
526 int res = pageNumEdit->text().toInt(&ok);
528 preview->setCurrentPage(res);
533 int curPage = preview->currentPage();
534 if (action == prevPageAction)
535 preview->setCurrentPage(curPage - 1);
536 else if (action == nextPageAction)
537 preview->setCurrentPage(curPage + 1);
538 else if (action == firstPageAction)
539 preview->setCurrentPage(1);
540 else if (action == lastPageAction)
541 preview->setCurrentPage(preview->pageCount());
547 if (action == overviewModeAction) {
550 fitGroup->setEnabled(
false);
551 navGroup->setEnabled(
false);
552 pageNumEdit->setEnabled(
false);
553 pageNumLabel->setEnabled(
false);
554 }
else if (action == facingModeAction) {
559 if (action == facingModeAction || action == singleModeAction) {
560 fitGroup->setEnabled(
true);
561 navGroup->setEnabled(
true);
562 pageNumEdit->setEnabled(
true);
563 pageNumLabel->setEnabled(
true);
572 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) 588 printer->setOutputFileName(fileName);
590 if (!printer->outputFileName().isEmpty())
613 portraitAction->setChecked(
true);
614 preview->setPortraitOrientation();
616 landscapeAction->setChecked(
true);
617 preview->setLandscapeOrientation();
625 updatePageNumLabel();
636 preview->setZoomFactor(factor/100.0);
724 delete d->printDialog;
734 if (visible && !
d->initialized) {
735 d->preview->updatePreview();
736 d->initialized =
true;
748 if (
d->receiverToDisconnectOnClose) {
750 d->receiverToDisconnectOnClose,
d->memberToDisconnectOnClose);
751 d->receiverToDisconnectOnClose = 0;
753 d->memberToDisconnectOnClose.clear();
774 d->receiverToDisconnectOnClose = receiver;
775 d->memberToDisconnectOnClose = member;
803 #include "moc_qprintpreviewdialog.cpp" 804 #include "qprintpreviewdialog.moc" 806 #endif // QT_NO_PRINTPREVIEWDIALOG static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void _q_navigate(QAction *action)
void done(int result)
Reimplemented Function
virtual QMenu * createPopupMenu()
Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the ma...
float toFloat(bool *ok=0) const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
QActionGroup * printerGroup
#define QT_END_NAMESPACE
This macro expands to.
static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that will return a file name selected by the user...
QByteArray memberToDisconnectOnClose
void focusInEvent(QFocusEvent *)
em>Reimplemented Function
The QDialog class is the base class of dialog windows.
The QByteArray class provides an array of bytes.
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
void _q_fit(QAction *action)
int length() const
Returns the number of characters in this string.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
The QObject class is the base class of all Qt objects.
void _q_zoomFactorChanged()
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
The QActionGroup class groups actions together.
QActionGroup * orientationGroup
~QPrintPreviewDialog()
Destroys the QPrintPreviewDialog.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
static QLocale system()
Returns a QLocale object initialized to the system locale.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QPrintDialog * printDialog
The QPrintDialog class provides a dialog for specifying the printer's configuration.
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer...
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setEditable(bool editable)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
int size() const
Returns the number of characters in this string.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QAction * overviewModeAction
QAction * landscapeAction
The QPrinter class is a paint device that paints on a printer.
The QComboBox widget is a combined button and popup list.
QValidator::State validate(QString &, int &) const
Returns Acceptable if the string input contains a double that is within the valid range and is in the...
The QPrintPreviewDialog class provides a dialog for previewing and configuring page layouts for print...
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
void init(QPrinter *printer=0)
The State element defines configurations of objects and properties.
virtual void done(int)
Closes the dialog and sets its result code to r.
QPrintPreviewWidget * preview
QPrinter * printer()
Returns a pointer to the QPrinter object this dialog is currently operating on.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
QAction * singleModeAction
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
void updatePageNumLabel()
#define Q_DECLARE_PUBLIC(Class)
QString & append(QChar c)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QAction * pageSetupAction
void focusOutEvent(QFocusEvent *)
em>Reimplemented Function
QObject * parent() const
Returns a pointer to the parent object.
QString suffix() const
Returns the suffix of the file.
int result() const
In general returns the modal dialog's result code, Accepted or Rejected.
QPrintPreviewDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QMainWindow class provides a main application window.
void setIcon(const QIcon &icon)
The QLabel widget provides a text or image display.
QAction * firstPageAction
The QLineEdit widget is a one-line text editor.
QPointer< QObject > receiverToDisconnectOnClose
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
void _q_setMode(QAction *action)
void setVisible(bool visible)
Reimplemented Function
void open()
Shows the dialog as a window modal dialog, returning immediately.
The QSize class defines the size of a two-dimensional object using integer point precision.
The QVBoxLayout class lines up widgets vertically.
QPrintPreviewDialogPrivate()
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
The QFileInfo class provides system-independent file information.
void finished(int result)
This signal is emitted when the dialog's result code has been set, either by the user or by calling d...
void setVisible(bool visible)
Reimplemented Function
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size...
The QFocusEvent class contains event parameters for widget focus events.
bool setAlignment(QWidget *w, Qt::Alignment alignment)
Sets the alignment for widget w to alignment and returns true if w is found in this layout (not inclu...
The QAction class provides an abstract user interface action that can be inserted into widgets...
QAction * facingModeAction
The QDoubleValidator class provides range checking of floating-point numbers.
static void qt_setupActionIcon(QAction *action, const QLatin1String &name)
The QIcon class provides scalable icons in different modes and states.