Add a "Print preview" menu entry

This commit is contained in:
Olivier Teulière 2013-01-14 17:13:08 +01:00
parent 6f2ee6f9ff
commit 0ea56cc442
4 changed files with 174 additions and 144 deletions

View file

@ -7,6 +7,7 @@
<file>images/go-next.png</file>
<file>images/go-last.png</file>
<file>images/go-jump.png</file>
<file>images/print-preview.png</file>
<file>images/printer.png</file>
<file>images/preferences.png</file>
<file>images/playlist_16px.png</file>

BIN
qt/images/print-preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -26,6 +26,7 @@
#include <QtGui/QFileDialog>
#include <QtGui/QDockWidget>
#include <QtGui/QCloseEvent>
#include <QtGui/QPrintPreviewDialog>
#include <QtGui/QPrintDialog>
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
@ -376,6 +377,7 @@ void MainWindow::updateForGame(PublicGame *iGame)
if (iGame == NULL)
{
m_actionGameSaveAs->setEnabled(false);
m_actionGamePrintPreview->setEnabled(false);
m_actionGamePrint->setEnabled(false);
m_actionHistoryFirstTurn->setEnabled(false);
m_actionHistoryPrevTurn->setEnabled(false);
@ -412,6 +414,7 @@ void MainWindow::updateForGame(PublicGame *iGame)
}
else
{
m_actionGamePrintPreview->setEnabled(true);
m_actionGamePrint->setEnabled(true);
m_actionGameSaveAs->setEnabled(true);
m_actionSettingsDefineTables->setEnabled(iGame->getMode() == PublicGame::kARBITRATION);
@ -801,6 +804,9 @@ void MainWindow::createMenu()
m_actionGameSaveAs = addMenuAction(menuFile, _q("&Save as..."), _q("Ctrl+S"),
_q("Save the current game"), SLOT(onGameSaveAs()));
menuFile->addSeparator();
m_actionGamePrintPreview = addMenuAction(menuFile, _q("&Print preview..."), QString(""),
_q("Print preview"), SLOT(onGamePrintPreview()),
false, QIcon(":/images/print-preview.png"));
m_actionGamePrint = addMenuAction(menuFile, _q("&Print..."), _q("Ctrl+P"),
_q("Print the current game"), SLOT(onGamePrint()),
false, QIcon(":/images/printer.png"));
@ -1014,11 +1020,29 @@ void MainWindow::onGamePrint()
QPrinter printer(QPrinter::HighResolution);
QPrintDialog printDialog(&printer, this);
if (printDialog.exec() == QDialog::Accepted)
{
LOG_INFO("Printing game");
if (printDialog.exec() != QDialog::Accepted)
return;
QPainter painter(&printer);
LOG_INFO("Printing game");
print(&printer);
}
void MainWindow::onGamePrintPreview()
{
LOG_INFO("Print preview");
QPrintPreviewDialog previewDialog;
QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)),
this, SLOT(print(QPrinter*)));
previewDialog.exec();
}
void MainWindow::print(QPrinter *printer)
{
ASSERT(m_game != NULL, "No game in progress");
QPainter painter(printer);
const History &history = m_game->getHistory();
// Printing parameters (XXX: these could be configurable by the users)
@ -1043,7 +1067,7 @@ void MainWindow::onGamePrint()
static const unsigned int nbCols = sizeof(colWidths) / sizeof(int);
const unsigned int nbRows = history.getSize() + (SHOULD_ALIGN ? 1 : 2);
double scale = printer.pageRect().width() / double(TOTAL_WIDTH);
double scale = printer->pageRect().width() / double(TOTAL_WIDTH);
painter.scale(scale, scale);
QPen pen(painter.pen());
@ -1160,7 +1184,6 @@ void MainWindow::onGamePrint()
LOG_INFO("Game printed");
}
}
void MainWindow::onGameQuit()

View file

@ -48,6 +48,7 @@ class AuxWindow;
class TimerModel;
class QLabel;
class QAction;
class QPrinter;
class MainWindow: public QMainWindow
{
@ -75,6 +76,7 @@ private slots:
void onGameLoad();
void onGameLoadAutoSave();
void onGameSaveAs();
void onGamePrintPreview();
void onGamePrint();
void onGameQuit();
void onSettingsChooseDic();
@ -97,6 +99,9 @@ private slots:
void onHistoryLastTurn();
void onHistoryReplayTurn();
/// Print the game using the given printer
void print(QPrinter *printer);
/// Simply emit a beep with the system speakers
void beep();
@ -158,6 +163,7 @@ private:
ScoreWidget *m_scoresWidget;
/// Actions enabled or disabled depending on the game state
QAction *m_actionGamePrintPreview;
QAction *m_actionGamePrint;
QAction *m_actionGameSaveAs;
QAction *m_actionHistoryPrevTurn;