diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-30 13:19:10 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-30 13:19:10 (GMT) |
commit | 771a6a8fd6a31905859a40b729eac872efb20285 (patch) | |
tree | 1d4efaa11e0f7498c3c51db4b3995e04f5b81e5d /tools | |
parent | 951ee7c2995b4f5c1a61c72c8f53ff40a3a0b2d4 (diff) | |
download | Qt-771a6a8fd6a31905859a40b729eac872efb20285.zip Qt-771a6a8fd6a31905859a40b729eac872efb20285.tar.gz Qt-771a6a8fd6a31905859a40b729eac872efb20285.tar.bz2 |
Linguist: defers the creation of the QPrinter
On windows, if your default printer is not reachable it would take a
lot of time to fail to construct the print engine. During that time
the UI would be frozen on the splash screen.
Reviewed-by: ossi
Diffstat (limited to 'tools')
-rw-r--r-- | tools/linguist/linguist/mainwindow.cpp | 22 | ||||
-rw-r--r-- | tools/linguist/linguist/mainwindow.h | 6 |
2 files changed, 20 insertions, 8 deletions
diff --git a/tools/linguist/linguist/mainwindow.cpp b/tools/linguist/linguist/mainwindow.cpp index 2b1df39..bb79b19 100644 --- a/tools/linguist/linguist/mainwindow.cpp +++ b/tools/linguist/linguist/mainwindow.cpp @@ -82,6 +82,7 @@ #include <QMenuBar> #include <QMessageBox> #include <QPrintDialog> +#include <QPrinter> #include <QProcess> #include <QRegExp> #include <QSettings> @@ -257,6 +258,7 @@ bool FocusWatcher::eventFilter(QObject *, QEvent *event) MainWindow::MainWindow() : QMainWindow(0, Qt::Window), m_assistantProcess(0), + m_printer(0), m_findMatchCase(Qt::CaseInsensitive), m_findIgnoreAccelerators(true), m_findWhere(DataModel::NoLocation), @@ -503,6 +505,7 @@ MainWindow::~MainWindow() qDeleteAll(m_phraseBooks); delete m_dataModel; delete m_statistics; + delete m_printer; } void MainWindow::modelCountChanged() @@ -870,15 +873,22 @@ void MainWindow::releaseAll() releaseInternal(i); } +QPrinter *MainWindow::printer() +{ + if (!m_printer) + m_printer = new QPrinter; + return m_printer; +} + void MainWindow::print() { int pageNum = 0; - QPrintDialog dlg(&m_printer, this); + QPrintDialog dlg(printer(), this); if (dlg.exec()) { QApplication::setOverrideCursor(Qt::WaitCursor); - m_printer.setDocName(m_dataModel->condensedSrcFileNames(true)); + printer()->setDocName(m_dataModel->condensedSrcFileNames(true)); statusBar()->showMessage(tr("Printing...")); - PrintOut pout(&m_printer); + PrintOut pout(printer()); for (int i = 0; i < m_dataModel->contextCount(); ++i) { MultiContextItem *mc = m_dataModel->multiContextItem(i); @@ -1229,11 +1239,11 @@ void MainWindow::printPhraseBook(QAction *action) int pageNum = 0; - QPrintDialog dlg(&m_printer, this); + QPrintDialog dlg(printer(), this); if (dlg.exec()) { - m_printer.setDocName(phraseBook->fileName()); + printer()->setDocName(phraseBook->fileName()); statusBar()->showMessage(tr("Printing...")); - PrintOut pout(&m_printer); + PrintOut pout(printer()); pout.setRule(PrintOut::ThinRule); foreach (const Phrase *p, phraseBook->phrases()) { pout.setGuide(p->source()); diff --git a/tools/linguist/linguist/mainwindow.h b/tools/linguist/linguist/mainwindow.h index 167dfe4..3dedcb5 100644 --- a/tools/linguist/linguist/mainwindow.h +++ b/tools/linguist/linguist/mainwindow.h @@ -51,7 +51,6 @@ #include <QtCore/QLocale> #include <QtGui/QMainWindow> -#include <QtGui/QPrinter> QT_BEGIN_NAMESPACE @@ -60,6 +59,7 @@ class QAction; class QDialog; class QLabel; class QMenu; +class QPrinter; class QProcess; class QIcon; class QSortFilterProxyModel; @@ -200,6 +200,8 @@ private: void releaseInternal(int model); void saveInternal(int model); + QPrinter *printer(); + // FIXME: move to DataModel void updateDanger(const MultiDataIndex &index, bool verbose); @@ -226,7 +228,7 @@ private: QList<QHash<QString, QList<Phrase *> > > m_phraseDict; QList<PhraseBook *> m_phraseBooks; QMap<QAction *, PhraseBook *> m_phraseBookMenu[3]; - QPrinter m_printer; + QPrinter *m_printer; FindDialog *m_findDialog; QString m_findText; |