Added Print Button

Added Print Feature to MessagesDialog
Added Print Preview Feature

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@422 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-03-26 14:22:51 +00:00
parent 048e84630e
commit 8079660291
8 changed files with 519 additions and 61 deletions

View File

@ -92,6 +92,7 @@ HEADERS += rshare.h \
util/Widget.h \
util/rsversion.h \
util/RsAction.h \
util/printpreview.h \
gui/bwgraph/bwgraph.h \
gui/chat/PopupChatDialog.h \
gui/connect/ConnectDialog.h \
@ -245,6 +246,7 @@ SOURCES += main.cpp \
util/Widget.cpp \
util/rsversion.cpp \
util/RsAction.cpp \
util/printpreview.cpp \
gui/bwgraph/bwgraph.cpp \
gui/chat/PopupChatDialog.cpp \
gui/connect/ConnectDialog.cpp \
@ -331,13 +333,17 @@ macx {
win32 {
OBJECTS_DIR = temp/obj
RCC_DIR = temp/qrc
UI_DIR = temp/ui
MOC_DIR = temp/moc
RC_FILE = gui/images/retroshare_win.rc
LIBS += -L"../../../../lib" -lretroshare -lssl -lcrypto -lpthreadGC2d -lKadC -lminiupnpc -lz
LIBS += -lqcheckers -lsmplayer
LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32-cygwin -gdi32
LIBS += -lole32
LIBS += -lole32 -lwinmm
}

View File

@ -23,7 +23,7 @@
#include "MessagesDialog.h"
#include "msgs/ChanMsgDialog.h"
#include "gui/toaster/MessageToaster.h"
#include "util/printpreview.h"
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
@ -36,6 +36,8 @@
#include <QPoint>
#include <QMouseEvent>
#include <QPixmap>
#include <QPrintDialog>
#include <QPrinter>
#include <QDateTime>
#include <QHeaderView>
@ -62,6 +64,9 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage()));
connect(ui.removemessageButton, SIGNAL(clicked()), this, SLOT(removemessage()));
//connect(ui.printbutton, SIGNAL(clicked()), this, SLOT(print()));
connect(ui.actionPrint, SIGNAL(triggered()), this, SLOT(print()));
connect(ui.actionPrintPreview, SIGNAL(triggered()), this, SLOT(printpreview()));
connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview()));
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getallrecommended()));
@ -92,6 +97,19 @@ MessagesDialog::MessagesDialog(QWidget *parent)
msglheader->resizeSection ( 1, 100 );
msglheader->resizeSection ( 2, 100 );
msglheader->resizeSection ( 3, 200 );
ui.newmessageButton->setIcon(QIcon(QString(":/images/folder-draft24-pressed.png")));
ui.replymessageButton->setIcon(QIcon(QString(":/images/replymail-pressed.png")));
ui.removemessageButton->setIcon(QIcon(QString(":/images/deletemail-pressed.png")));
ui.printbutton->setIcon(QIcon(QString(":/images/print24.png")));
/*Disabled Reply Button */
ui.replymessageButton->setEnabled(false);
QMenu * printmenu = new QMenu();
printmenu->addAction(ui.actionPrint);
printmenu->addAction(ui.actionPrintPreview);
ui.printbutton->setMenu(printmenu);
/* Hide platform specific features */
@ -621,4 +639,26 @@ void MessagesDialog::markMsgAsRead()
return;
}
void MessagesDialog::print()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (ui.msgText->textCursor().hasSelection())
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if (dlg->exec() == QDialog::Accepted) {
ui.msgText->print(&printer);
}
delete dlg;
#endif
}
void MessagesDialog::printpreview()
{
PrintPreview *preview = new PrintPreview(ui.msgText->document(), this);
preview->setWindowModality(Qt::WindowModal);
preview->setAttribute(Qt::WA_DeleteOnClose);
preview->show();
}

View File

@ -53,6 +53,8 @@ void updateMessages ( QTreeWidgetItem * item, int column );
void newmessage();
void replytomessage();
void print();
void printpreview();
void removemessage();
void markMsgAsRead();

View File

@ -509,14 +509,14 @@
<widget class="QPushButton" name="newmessageButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -526,20 +526,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">New Message&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="styleSheet" >
<string>QPushButton
{
border-image: url(:/images/folder-draft24.png);
}
QPushButton:hover
{
border-image: url(:/images/folder-draft24-hover.png);
}
QPushButton:pressed
{
border-image: url(:/images/folder-draft24-pressed.png);
}
</string>
<string/>
</property>
<property name="text" >
<string/>
@ -559,14 +546,14 @@ border-image: url(:/images/folder-draft24-pressed.png);
<widget class="QPushButton" name="replymessageButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -576,22 +563,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">reply to selected message&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="styleSheet" >
<string>
QPushButton
{
border-image: url(:/images/replymail24.png);
}
QPushButton:hover
{
border-image: url(:/images/replymail24-hover.png);
}
QPushButton:pressed
{
border-image: url(:/images/replymail-pressed.png);
}
</string>
<string/>
</property>
<property name="text" >
<string/>
@ -608,14 +580,14 @@ border-image: url(:/images/replymail-pressed.png);
<widget class="QPushButton" name="removemessageButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -625,20 +597,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">remove selected message&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="styleSheet" >
<string>QPushButton
{
border-image: url(:/images/deletemail24.png);
}
QPushButton:hover
{
border-image: url(:/images/deletemail-hover.png);
}
QPushButton:pressed
{
border-image: url(:/images/deletemail-pressed.png);
}</string>
<string/>
</property>
<property name="text" >
<string/>
@ -652,19 +611,50 @@ border-image: url(:/images/deletemail-pressed.png);
</widget>
</item>
<item row="0" column="3" >
<widget class="QPushButton" name="printbutton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item row="0" column="4" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
<width>571</width>
<height>24</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="4" >
<item row="1" column="0" colspan="5" >
<widget class="QSplitter" name="splitter_2" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
@ -1180,6 +1170,16 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
</layout>
<action name="actionPrint" >
<property name="text" >
<string>Print</string>
</property>
</action>
<action name="actionPrintPreview" >
<property name="text" >
<string>PrintPreview</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>newmessageButton</tabstop>

View File

@ -155,6 +155,7 @@
<file>images/peerdetails_16x16.png</file>
<file>images/peers_16x16.png</file>
<file>images/peers_24x24.png</file>
<file>images/print24.png</file>
<file>images/removefriend16.png</file>
<file>images/replymail-pressed.png</file>
<file>images/replymail24-hover.png</file>
@ -192,6 +193,8 @@
<file>images/textedit/fileopen.png</file>
<file>images/textedit/fileprint.png</file>
<file>images/textedit/filesave.png</file>
<file>images/textedit/zoomin.png</file>
<file>images/textedit/zoomout.png</file>
<file>images/toaster/chat.png</file>
<file>images/toaster/hangup.png</file>
<file>images/toaster/pickup.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,334 @@
/****************************************************************************
**
** Copyright (C) 2004-2007 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.0, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** In addition, as a special exception, Trolltech, as the sole copyright
** holder for Qt Designer, grants users of the Qt/Eclipse Integration
** plug-in the right for the Qt/Eclipse Integration to link to
** functionality provided by Qt Designer and its related libraries.
**
** Trolltech reserves all rights not expressly granted herein.
**
** Trolltech ASA (c) 2007
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "printpreview.h"
#include <QAbstractScrollArea>
#include <QPrintDialog>
#include <QPrinter>
#include <QToolBar>
#include <QAction>
#include <QTextFormat>
#include <QMouseEvent>
#include <QTextFrame>
#include <QTextDocument>
#include <QAbstractTextDocumentLayout>
#include <QScrollBar>
#include <QPainter>
#include <QDebug>
#include <QPageSetupDialog>
#include <QStatusBar>
#ifdef Q_WS_MAC
const QString rsrcPath = ":/images/mac";
#else
const QString rsrcPath = ":/images/win";
#endif
static inline int inchesToPixels(float inches, QPaintDevice *device)
{
return qRound(inches * device->logicalDpiY());
}
static inline qreal mmToInches(double mm)
{
return mm*0.039370147;
}
class PreviewView : public QAbstractScrollArea
{
Q_OBJECT
public:
PreviewView(QTextDocument *document, PrintPreview *printPrev);
inline void updateLayout() { resizeEvent(0); viewport()->update(); }
public slots:
void zoomIn();
void zoomOut();
protected:
virtual void paintEvent(QPaintEvent *e);
virtual void resizeEvent(QResizeEvent *);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseMoveEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e);
private:
void paintPage(QPainter *painter, int page);
QTextDocument *doc;
qreal scale;
int interPageSpacing;
QPoint mousePressPos;
QPoint scrollBarValuesOnMousePress;
PrintPreview *printPreview;
};
PreviewView::PreviewView(QTextDocument *document, PrintPreview *printPrev)
: printPreview(printPrev)
{
verticalScrollBar()->setSingleStep(20);
horizontalScrollBar()->setSingleStep(20);
viewport()->setBackgroundRole(QPalette::Dark);
doc = document;
scale = 1.0;
interPageSpacing = 30;
}
void PreviewView::zoomIn()
{
scale += 0.2;
resizeEvent(0);
viewport()->update();
}
void PreviewView::zoomOut()
{
scale -= 0.2;
resizeEvent(0);
viewport()->update();
}
void PreviewView::paintEvent(QPaintEvent *)
{
QPainter p(viewport());
p.translate(-horizontalScrollBar()->value(), -verticalScrollBar()->value());
p.translate(interPageSpacing, interPageSpacing);
const int pages = doc->pageCount();
for (int i = 0; i < pages; ++i) {
p.save();
p.scale(scale, scale);
paintPage(&p, i);
p.restore();
p.translate(0, interPageSpacing + printPreview->paperSize.height() * scale);
}
}
void PreviewView::paintPage(QPainter *painter, int page)
{
const QSizeF pgSize = doc->pageSize();
QColor col(Qt::black);
painter->setPen(col);
painter->setBrush(Qt::white);
painter->drawRect(QRectF(QPointF(0, 0), printPreview->paperSize));
painter->setBrush(Qt::NoBrush);
col = col.light();
painter->drawLine(QLineF(printPreview->paperSize.width(), 1,
printPreview->paperSize.width(), printPreview->paperSize.height() - 1));
col = col.light();
painter->drawLine(QLineF(printPreview->paperSize.width(), 2,
printPreview->paperSize.width(), printPreview->paperSize.height() - 2));
QRectF docRect(QPointF(0, page * pgSize.height()), pgSize);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.clip = docRect;
// don't use the system palette text as default text color, on HP/UX
// for example that's white, and white text on white paper doesn't
// look that nice
ctx.palette.setColor(QPalette::Text, Qt::black);
painter->translate(0, - page * pgSize.height());
painter->translate(printPreview->pageTopLeft);
painter->setClipRect(docRect);//.translated(printPreview->pageTopLeft));
doc->documentLayout()->draw(painter, ctx);
}
void PreviewView::resizeEvent(QResizeEvent *)
{
const QSize viewportSize = viewport()->size();
QSize docSize;
docSize.setWidth(qRound(printPreview->paperSize.width() * scale + 2 * interPageSpacing));
const int pageCount = doc->pageCount();
docSize.setHeight(qRound(pageCount * printPreview->paperSize.height() * scale + (pageCount + 1) * interPageSpacing));
horizontalScrollBar()->setRange(0, docSize.width() - viewportSize.width());
horizontalScrollBar()->setPageStep(viewportSize.width());
verticalScrollBar()->setRange(0, docSize.height() - viewportSize.height());
verticalScrollBar()->setPageStep(viewportSize.height());
}
void PreviewView::mousePressEvent(QMouseEvent *e)
{
mousePressPos = e->pos();
scrollBarValuesOnMousePress.rx() = horizontalScrollBar()->value();
scrollBarValuesOnMousePress.ry() = verticalScrollBar()->value();
e->accept();
}
void PreviewView::mouseMoveEvent(QMouseEvent *e)
{
if (mousePressPos.isNull()) {
e->ignore();
return;
}
horizontalScrollBar()->setValue(scrollBarValuesOnMousePress.x() - e->pos().x() + mousePressPos.x());
verticalScrollBar()->setValue(scrollBarValuesOnMousePress.y() - e->pos().y() + mousePressPos.y());
horizontalScrollBar()->update();
verticalScrollBar()->update();
e->accept();
}
void PreviewView::mouseReleaseEvent(QMouseEvent *e)
{
mousePressPos = QPoint();
e->accept();
}
PrintPreview::PrintPreview(const QTextDocument *document, QWidget *parent)
: QMainWindow(parent), printer(QPrinter::HighResolution)
{
setWindowTitle(tr("RetroShare Message - Print Preview"));
printer.setFullPage(true);
doc = document->clone();
view = new PreviewView(doc, this);
setCentralWidget(view);
resize(800, 600);
doc->setUseDesignMetrics(true);
doc->documentLayout()->setPaintDevice(view->viewport());
// add a nice 2 cm margin
const qreal margin = inchesToPixels(mmToInches(20), this);
QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
fmt.setMargin(margin);
doc->rootFrame()->setFrameFormat(fmt);
setup();
QFont f(doc->defaultFont());
f.setPointSize(10);
doc->setDefaultFont(f);
QToolBar *tb = addToolBar(tr("Print"));
tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QAction *a;
a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("&Print..."), this);
a->setShortcut(Qt::CTRL + Qt::Key_P);
connect(a, SIGNAL(triggered()), this, SLOT(print()));
tb->addAction(a);
a = new QAction(this);
a->setText(tr("Page Setup..."));
connect(a, SIGNAL(triggered()), this, SLOT(pageSetup()));
tb->addAction(a);
tb->addSeparator();
a = new QAction(QIcon(":/images/textedit/zoomin.png"), tr("Zoom In"), this);
connect(a, SIGNAL(triggered()), view, SLOT(zoomIn()));
tb->addAction(a);
a = new QAction(QIcon(":/images/textedit/zoomout.png"), tr("Zoom Out"), this);
connect(a, SIGNAL(triggered()), view, SLOT(zoomOut()));
tb->addAction(a);
tb->addSeparator();
a = new QAction(this);
a->setText(tr("&Close"));
connect(a, SIGNAL(triggered()), this, SLOT(close()));
tb->addAction(a);
statusBar()->setSizeGripEnabled(true);
}
void PrintPreview::setup()
{
QSizeF page = printer.pageRect().size();
paperSize = printer.paperRect().size();
paperSize.rwidth() *= qreal(view->logicalDpiX()) / printer.logicalDpiX();
paperSize.rheight() *= qreal(view->logicalDpiY()) / printer.logicalDpiY();
pageTopLeft = printer.pageRect().topLeft();
pageTopLeft.rx() *= qreal(view->logicalDpiX()) / printer.logicalDpiX();
pageTopLeft.ry() *= qreal(view->logicalDpiY()) / printer.logicalDpiY();
page.setWidth(page.width() * view->logicalDpiX() / printer.logicalDpiX());
page.setHeight(page.height() * view->logicalDpiY() / printer.logicalDpiY());
// add a nice 2 cm margin
const qreal margin = inchesToPixels(mmToInches(20), this);
QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
fmt.setMargin(margin);
doc->rootFrame()->setFrameFormat(fmt);
doc->setPageSize(page);
}
PrintPreview::~PrintPreview()
{
delete doc;
}
void PrintPreview::print()
{
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (dlg->exec() == QDialog::Accepted) {
doc->print(&printer);
}
delete dlg;
}
void PrintPreview::pageSetup()
{
QPageSetupDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted) {
setup();
view->updateLayout();
}
}
#include "printpreview.moc"

View File

@ -0,0 +1,73 @@
/****************************************************************************
**
** Copyright (C) 2004-2007 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.0, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** In addition, as a special exception, Trolltech, as the sole copyright
** holder for Qt Designer, grants users of the Qt/Eclipse Integration
** plug-in the right for the Qt/Eclipse Integration to link to
** functionality provided by Qt Designer and its related libraries.
**
** Trolltech reserves all rights not expressly granted herein.
**
** Trolltech ASA (c) 2007
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef PRINTPREVIEW_H
#define PRINTPREVIEW_H
#include <QMainWindow>
#include <QPrinter>
#include <QPointF>
#include <QSizeF>
class PreviewView;
class QTextDocument;
class PrintPreview : public QMainWindow
{
Q_OBJECT
public:
PrintPreview(const QTextDocument *document, QWidget *parent);
virtual ~PrintPreview();
QSizeF paperSize;
QPointF pageTopLeft;
private slots:
void print();
void pageSetup();
private:
void setup();
QTextDocument *doc;
PreviewView *view;
QPrinter printer;
};
#endif // PRINTPREVIEW_H