diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 47b71d118..ec9a60bdf 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -44,11 +44,12 @@ /* Images for context menu icons */ -#define IMAGE_MESSAGE ":/images/folder-draft.png" -#define IMAGE_MESSAGEREPLY ":/images/mail_reply.png" -#define IMAGE_MESSAGEREMOVE ":/images/mail_delete.png" -#define IMAGE_DOWNLOAD ":/images/start.png" -#define IMAGE_DOWNLOADALL ":/images/startall.png" +#define IMAGE_MESSAGE ":/images/folder-draft.png" +#define IMAGE_MESSAGEREPLY ":/images/mail_reply.png" +#define IMAGE_MESSAGEFORWARD ":/images/mail_forward.png" +#define IMAGE_MESSAGEREMOVE ":/images/message-mail-imapdelete.png" +#define IMAGE_DOWNLOAD ":/images/start.png" +#define IMAGE_DOWNLOADALL ":/images/startall.png" /** Constructor */ @@ -66,6 +67,8 @@ MessagesDialog::MessagesDialog(QWidget *parent) connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage())); connect(ui.removemessageButton, SIGNAL(clicked()), this, SLOT(removemessage())); connect(ui.replymessageButton, SIGNAL(clicked()), this, SLOT(replytomessage())); + connect(ui.forwardmessageButton, SIGNAL(clicked()), this, SLOT(forwardmessage())); + //connect(ui.printbutton, SIGNAL(clicked()), this, SLOT(print())); connect(ui.actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(ui.actionPrintPreview, SIGNAL(triggered()), this, SLOT(printpreview())); @@ -103,19 +106,21 @@ MessagesDialog::MessagesDialog(QWidget *parent) 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); - + ui.replymessageButton->setIcon(QIcon(QString(":/images/replymail-pressed.png"))); + ui.forwardmessageButton->setIcon(QIcon(QString(":/images/mailforward24-hover.png"))); + ui.removemessageButton->setIcon(QIcon(QString(":/images/deletemail-pressed.png"))); + ui.printbutton->setIcon(QIcon(QString(":/images/print24.png"))); + + ui.forwardmessageButton->setToolTip(tr("Forward selected Message")); + + QMenu * printmenu = new QMenu(); printmenu->addAction(ui.actionPrint); printmenu->addAction(ui.actionPrintPreview); ui.printbutton->setMenu(printmenu); ui.msgWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui.msgWidget->sortItems( 3, Qt::DescendingOrder ); /* Hide platform specific features */ @@ -160,6 +165,12 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point ) connect( replytomsgAct , SIGNAL( triggered() ), this, SLOT( replytomessage() ) ); contextMnu.addAction( replytomsgAct); + forwardmsgAct = new QAction(QIcon(IMAGE_MESSAGEFORWARD), tr( "Forward Message" ), this ); + connect( forwardmsgAct , SIGNAL( triggered() ), this, SLOT( forwardmessage() ) ); + contextMnu.addAction( forwardmsgAct); + + contextMnu.addSeparator(); + removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Message" ), this ); connect( removemsgAct , SIGNAL( triggered() ), this, SLOT( removemessage() ) ); contextMnu.addAction( removemsgAct); @@ -225,6 +236,8 @@ void MessagesDialog::replytomessage() //std::cerr << "MessagesDialog::newmessage()" << std::endl; nMsgDialog->newMsg(); nMsgDialog->insertTitleText( (QString("Re: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; + nMsgDialog->setWindowTitle(tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; + QTextDocument doc ; doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; @@ -236,6 +249,41 @@ void MessagesDialog::replytomessage() nMsgDialog->activateWindow(); } +void MessagesDialog::forwardmessage() +{ + /* put msg on msgBoard, and switch to it. */ + + std::string cid; + std::string mid; + + if(!getCurrentMsg(cid, mid)) + return ; + + mCurrCertId = cid; + mCurrMsgId = mid; + + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mid, msgInfo)) + return ; + + ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); + /* fill it in */ + //std::cerr << "MessagesDialog::newmessage()" << std::endl; + nMsgDialog->newMsg(); + nMsgDialog->insertTitleText( (QString("Fwd: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; + nMsgDialog->setWindowTitle(tr("Fwd: ") + QString::fromStdWString(msgInfo.title) ) ; + + + QTextDocument doc ; + doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; + std::string cited_text(doc.toPlainText().toStdString()) ; + + nMsgDialog->insertForwardPastedText(cited_text) ; + nMsgDialog->addRecipient( msgInfo.srcId ) ; + nMsgDialog->show(); + nMsgDialog->activateWindow(); +} + void MessagesDialog::togglefileview() { /* if msg header visible -> hide by changing splitter @@ -459,6 +507,7 @@ void MessagesDialog::insertMessages() std::ostringstream out; out << it -> count; item -> setText(0, QString::fromStdString(out.str())); + item -> setTextAlignment( 0, Qt::AlignCenter ); } item -> setText(4, QString::fromStdString(it->srcId)); diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index 183572f30..1119eb5ca 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -17,34 +17,34 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. - ****************************************************************/ - -#ifndef _MESSAGESDIALOG_H -#define _MESSAGESDIALOG_H - -#include + ****************************************************************/ + +#ifndef _MESSAGESDIALOG_H +#define _MESSAGESDIALOG_H + +#include + +#include "mainpage.h" +#include "ui_MessagesDialog.h" + +class MessagesDialog : public MainPage +{ + Q_OBJECT + +public: + /** Default Constructor */ + MessagesDialog(QWidget *parent = 0); + /** Default Destructor */ -#include "mainpage.h" -#include "ui_MessagesDialog.h" - -class MessagesDialog : public MainPage -{ - Q_OBJECT - -public: - /** Default Constructor */ - MessagesDialog(QWidget *parent = 0); - /** Default Destructor */ - void insertMessages(); void insertMsgTxtAndFiles(); - - + + virtual void keyPressEvent(QKeyEvent *) ; -private slots: - - /** Create the context popup menu and it's submenus */ +private slots: + + /** Create the context popup menu and it's submenus */ void messageslistWidgetCostumPopupMenu( QPoint point ); void msgfilelistWidgetCostumPopupMenu(QPoint); @@ -52,14 +52,16 @@ void changeBox( int newrow ); void updateMessages ( QTreeWidgetItem * item, int column ); void newmessage(); - + void replytomessage(); + void forwardmessage(); + void print(); - void printpreview(); + void printpreview(); void removemessage(); void markMsgAsRead(); - + void getcurrentrecommended(); void getallrecommended(); @@ -72,21 +74,22 @@ private: std::string mCurrCertId; std::string mCurrMsgId; - - /** Define the popup menus for the Context menu */ + + /** Define the popup menus for the Context menu */ QMenu* contextMnu; - /** Defines the actions for the context menu */ - QAction* newmsgAct; + /** Defines the actions for the context menu */ + QAction* newmsgAct; QAction* replytomsgAct; + QAction* forwardmsgAct; QAction* removemsgAct; QAction* getRecAct; QAction* getAllRecAct; - /** Qt Designer generated object */ - Ui::MessagesDialog ui; -}; - -#endif - + /** Qt Designer generated object */ + Ui::MessagesDialog ui; +}; + +#endif + diff --git a/retroshare-gui/src/gui/MessagesDialog.ui b/retroshare-gui/src/gui/MessagesDialog.ui index 3b43fdf80..380fdfc78 100644 --- a/retroshare-gui/src/gui/MessagesDialog.ui +++ b/retroshare-gui/src/gui/MessagesDialog.ui @@ -6,7 +6,7 @@ 0 0 759 - 530 + 520 @@ -577,6 +577,31 @@ p, li { white-space: pre-wrap; } + + + + 28 + 28 + + + + + 28 + 28 + + + + + + + + 24 + 24 + + + + + @@ -610,7 +635,7 @@ p, li { white-space: pre-wrap; } - + @@ -641,20 +666,20 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal - 602 - 24 + 541 + 20 - + Qt::Horizontal diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 5296b8e08..46dbcb497 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -192,11 +192,14 @@ images/mail_delete.png images/mail_get.png images/mail_reply.png + images/mail_forward.png images/mail_send.png images/mail_new.png images/mail_send24.png + images/mailforward24-hover.png images/message-mail.png - images/message-mail-read.pngm + images/message-mail-read.png + images/message-mail-imapdelete.png images/message-news.png images/message.png images/messenger.png diff --git a/retroshare-gui/src/gui/images/mail_forward.png b/retroshare-gui/src/gui/images/mail_forward.png new file mode 100755 index 000000000..833360b24 Binary files /dev/null and b/retroshare-gui/src/gui/images/mail_forward.png differ diff --git a/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp b/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp index eba52685c..4cd22886f 100644 --- a/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp +++ b/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp @@ -17,16 +17,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. - ****************************************************************/ - -#include "rshare.h" -#include "ChanMsgDialog.h" - + ****************************************************************/ + +#include "rshare.h" +#include "ChanMsgDialog.h" + #include "rsiface/rsiface.h" #include "rsiface/rspeers.h" #include "rsiface/rsmsgs.h" -#include +#include #include @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -43,22 +43,22 @@ #include #include #include -#include +#include #include #include -#include -#include -#include +#include +#include +#include #include #include #include - -/** Constructor */ -ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) -: mIsMsg(msg), QMainWindow(parent, flags) -{ - /* Invoke the Qt Designer generated object setup routine */ + +/** Constructor */ +ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) +: mIsMsg(msg), QMainWindow(parent, flags) +{ + /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -67,12 +67,12 @@ ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) setupViewActions(); setupInsertActions(); - RshareSettings config; + RshareSettings config; config.loadWidgetInformation(this); setAttribute ( Qt::WA_DeleteOnClose, true ); - //connect( ui.channelstreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( channelstreeViewCostumPopupMenu( QPoint ) ) ); + //connect( ui.channelstreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( channelstreeViewCostumPopupMenu( QPoint ) ) ); // // connect up the buttons. @@ -87,38 +87,38 @@ ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) connect(ui.actionContactsView, SIGNAL(triggered()), this, SLOT(toggleContacts())); connect(ui.actionSaveas, SIGNAL(triggered()), this, SLOT(fileSaveAs())); - connect(ui.msgText, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), - this, SLOT(currentCharFormatChanged(const QTextCharFormat &))); - connect(ui.msgText, SIGNAL(cursorPositionChanged()), + connect(ui.msgText, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), + this, SLOT(currentCharFormatChanged(const QTextCharFormat &))); + connect(ui.msgText, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged())); - connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)), - actionSave, SLOT(setEnabled(bool))); - connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)), - this, SLOT(setWindowModified(bool))); - connect(ui.msgText->document(), SIGNAL(undoAvailable(bool)), - actionUndo, SLOT(setEnabled(bool))); - connect(ui.msgText->document(), SIGNAL(redoAvailable(bool)), - actionRedo, SLOT(setEnabled(bool))); - - setWindowModified(ui.msgText->document()->isModified()); - actionSave->setEnabled(ui.msgText->document()->isModified()); - actionUndo->setEnabled(ui.msgText->document()->isUndoAvailable()); - actionRedo->setEnabled(ui.msgText->document()->isRedoAvailable()); - - connect(actionUndo, SIGNAL(triggered()), ui.msgText, SLOT(undo())); - connect(actionRedo, SIGNAL(triggered()), ui.msgText, SLOT(redo())); - - actionCut->setEnabled(false); - actionCopy->setEnabled(false); - - connect(actionCut, SIGNAL(triggered()), ui.msgText, SLOT(cut())); - connect(actionCopy, SIGNAL(triggered()), ui.msgText, SLOT(copy())); - connect(actionPaste, SIGNAL(triggered()), ui.msgText, SLOT(paste())); - - connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool))); - connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool))); - + connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)), + actionSave, SLOT(setEnabled(bool))); + connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)), + this, SLOT(setWindowModified(bool))); + connect(ui.msgText->document(), SIGNAL(undoAvailable(bool)), + actionUndo, SLOT(setEnabled(bool))); + connect(ui.msgText->document(), SIGNAL(redoAvailable(bool)), + actionRedo, SLOT(setEnabled(bool))); + + setWindowModified(ui.msgText->document()->isModified()); + actionSave->setEnabled(ui.msgText->document()->isModified()); + actionUndo->setEnabled(ui.msgText->document()->isUndoAvailable()); + actionRedo->setEnabled(ui.msgText->document()->isRedoAvailable()); + + connect(actionUndo, SIGNAL(triggered()), ui.msgText, SLOT(undo())); + connect(actionRedo, SIGNAL(triggered()), ui.msgText, SLOT(redo())); + + actionCut->setEnabled(false); + actionCopy->setEnabled(false); + + connect(actionCut, SIGNAL(triggered()), ui.msgText, SLOT(cut())); + connect(actionCopy, SIGNAL(triggered()), ui.msgText, SLOT(copy())); + connect(actionPaste, SIGNAL(triggered()), ui.msgText, SLOT(paste())); + + connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool))); + connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool))); + connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged())); /* if Msg */ @@ -140,43 +140,43 @@ ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) ui.msgSendList -> setRootIsDecorated( false ); ui.msgFileList -> setRootIsDecorated( false ); - /* to hide the header */ + /* to hide the header */ //ui.msgSendList->header()->hide(); - QActionGroup *grp = new QActionGroup(this); - connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(textAlign(QAction *))); - - actionAlignLeft = new QAction(QIcon(":/images/textedit/textleft.png"), tr("&Left"), grp); - actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L); - actionAlignLeft->setCheckable(true); - actionAlignCenter = new QAction(QIcon(":/images/textedit/textcenter.png"), tr("C&enter"), grp); - actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E); - actionAlignCenter->setCheckable(true); - actionAlignRight = new QAction(QIcon(":/images/textedit/textright.png"), tr("&Right"), grp); - actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R); - actionAlignRight->setCheckable(true); - actionAlignJustify = new QAction(QIcon(":/images/textedit/textjustify.png"), tr("&Justify"), grp); - actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J); + QActionGroup *grp = new QActionGroup(this); + connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(textAlign(QAction *))); + + actionAlignLeft = new QAction(QIcon(":/images/textedit/textleft.png"), tr("&Left"), grp); + actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L); + actionAlignLeft->setCheckable(true); + actionAlignCenter = new QAction(QIcon(":/images/textedit/textcenter.png"), tr("C&enter"), grp); + actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E); + actionAlignCenter->setCheckable(true); + actionAlignRight = new QAction(QIcon(":/images/textedit/textright.png"), tr("&Right"), grp); + actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R); + actionAlignRight->setCheckable(true); + actionAlignJustify = new QAction(QIcon(":/images/textedit/textjustify.png"), tr("&Justify"), grp); + actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J); actionAlignJustify->setCheckable(true); - ui.comboStyle->addItem("Standard"); - ui.comboStyle->addItem("Bullet List (Disc)"); - ui.comboStyle->addItem("Bullet List (Circle)"); - ui.comboStyle->addItem("Bullet List (Square)"); - ui.comboStyle->addItem("Ordered List (Decimal)"); - ui.comboStyle->addItem("Ordered List (Alpha lower)"); - ui.comboStyle->addItem("Ordered List (Alpha upper)"); + ui.comboStyle->addItem("Standard"); + ui.comboStyle->addItem("Bullet List (Disc)"); + ui.comboStyle->addItem("Bullet List (Circle)"); + ui.comboStyle->addItem("Bullet List (Square)"); + ui.comboStyle->addItem("Ordered List (Decimal)"); + ui.comboStyle->addItem("Ordered List (Alpha lower)"); + ui.comboStyle->addItem("Ordered List (Alpha upper)"); connect(ui.comboStyle, SIGNAL(activated(int)),this, SLOT(textStyle(int))); connect(ui.comboFont, SIGNAL(activated(const QString &)), this, SLOT(textFamily(const QString &))); - ui.comboSize->setEditable(true); - - QFontDatabase db; - foreach(int size, db.standardSizes()) - ui.comboSize->addItem(QString::number(size)); - - connect(ui.comboSize, SIGNAL(activated(const QString &)),this, SLOT(textSize(const QString &))); + ui.comboSize->setEditable(true); + + QFontDatabase db; + foreach(int size, db.standardSizes()) + ui.comboSize->addItem(QString::number(size)); + + connect(ui.comboSize, SIGNAL(activated(const QString &)),this, SLOT(textSize(const QString &))); ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(QApplication::font().pointSize()))); ui.boldbtn->setIcon(QIcon(QString(":/images/textedit/textbold.png"))); @@ -193,42 +193,42 @@ ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags) ui.actionSaveas->setStatusTip(tr("Save this message")); - QMenu * alignmentmenu = new QMenu(); - alignmentmenu->addAction(actionAlignLeft); - alignmentmenu->addAction(actionAlignCenter); - alignmentmenu->addAction(actionAlignRight); - alignmentmenu->addAction(actionAlignJustify); + QMenu * alignmentmenu = new QMenu(); + alignmentmenu->addAction(actionAlignLeft); + alignmentmenu->addAction(actionAlignCenter); + alignmentmenu->addAction(actionAlignRight); + alignmentmenu->addAction(actionAlignJustify); ui.textalignmentbtn->setMenu(alignmentmenu); - QPixmap pxm(24,24); + QPixmap pxm(24,24); pxm.fill(Qt::black); ui.colorbtn->setIcon(pxm); - /* Hide platform specific features */ -#ifdef Q_WS_WIN - -#endif -} + /* Hide platform specific features */ +#ifdef Q_WS_WIN + +#endif +} -void ChanMsgDialog::channelstreeViewCostumPopupMenu( QPoint point ) -{ - - QMenu contextMnu( this ); - QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); - - deletechannelAct = new QAction( tr( "Delete Channel" ), this ); +void ChanMsgDialog::channelstreeViewCostumPopupMenu( QPoint point ) +{ + + QMenu contextMnu( this ); + QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); + + deletechannelAct = new QAction( tr( "Delete Channel" ), this ); connect( deletechannelAct , SIGNAL( triggered() ), this, SLOT( deletechannel() ) ); - createchannelmsgAct = new QAction( tr( "Create Channel MSG" ), this ); - connect( createchannelmsgAct , SIGNAL( triggered() ), this, SLOT( createchannelmsg() ) ); - - - contextMnu.clear(); + createchannelmsgAct = new QAction( tr( "Create Channel MSG" ), this ); + connect( createchannelmsgAct , SIGNAL( triggered() ), this, SLOT( createchannelmsg() ) ); + + + contextMnu.clear(); contextMnu.addAction( deletechannelAct); - contextMnu.addAction( createchannelmsgAct); - contextMnu.exec( mevent->globalPos() ); -} + contextMnu.addAction( createchannelmsgAct); + contextMnu.exec( mevent->globalPos() ); +} void ChanMsgDialog::closeEvent (QCloseEvent * event) { @@ -243,33 +243,33 @@ void ChanMsgDialog::closeEvent (QCloseEvent * event) if (maybeSave()) { event->accept(); - } + } else { event->ignore(); hide(); - RshareSettings config; + RshareSettings config; config.saveWidgetInformation(this); } #endif } - -void ChanMsgDialog::deletechannel() -{ - +void ChanMsgDialog::deletechannel() +{ + + } -void ChanMsgDialog::createchannelmsg() -{ +void ChanMsgDialog::createchannelmsg() +{ + - } - - + + void ChanMsgDialog::insertSendList() { @@ -514,6 +514,15 @@ void ChanMsgDialog::insertPastedText(std::string msg) ui.msgText->setHtml(QString("")+QString::fromStdString(std::string("> ") + msg)+"

") ; } +void ChanMsgDialog::insertForwardPastedText(std::string msg) +{ + std::string::size_type i=0 ; + while( (i=msg.find_first_of('\n',i+1)) < msg.size()) + msg.replace(i,1,std::string("\n
> ")) ; + + ui.msgText->setHtml(QString("
")+QString::fromStdString(std::string("") + msg)+"

") ; +} + void ChanMsgDialog::insertMsgText(std::string msg) { ui.msgText->setText(QString::fromStdString(msg)); @@ -642,443 +651,443 @@ void ChanMsgDialog::toggleRecommendItem( QTreeWidgetItem *item, int col ) rsicontrol -> SetInRecommend(id, inRecommend); return; } - -void ChanMsgDialog::setupFileActions() -{ - QMenu *menu = new QMenu(tr("&File"), this); - menuBar()->addMenu(menu); - - QAction *a; - - a = new QAction(QIcon(":/images/textedit/filenew.png"), tr("&New"), this); - a->setShortcut(QKeySequence::New); - connect(a, SIGNAL(triggered()), this, SLOT(fileNew())); - menu->addAction(a); - - a = new QAction(QIcon(":/images/textedit/fileopen.png"), tr("&Open..."), this); - a->setShortcut(QKeySequence::Open); - connect(a, SIGNAL(triggered()), this, SLOT(fileOpen())); - menu->addAction(a); - - menu->addSeparator(); - - actionSave = a = new QAction(QIcon(":/images/textedit/filesave.png"), tr("&Save"), this); - a->setShortcut(QKeySequence::Save); - connect(a, SIGNAL(triggered()), this, SLOT(fileSave())); - a->setEnabled(false); - menu->addAction(a); - - a = new QAction(tr("Save &As..."), this); - connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs())); - menu->addAction(a); - menu->addSeparator(); - - a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("&Print..."), this); - a->setShortcut(QKeySequence::Print); - connect(a, SIGNAL(triggered()), this, SLOT(filePrint())); - menu->addAction(a); - - /*a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("Print Preview..."), this); - connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview())); - menu->addAction(a);*/ - - a = new QAction(QIcon(":/images/textedit/exportpdf.png"), tr("&Export PDF..."), this); - a->setShortcut(Qt::CTRL + Qt::Key_D); - connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf())); - menu->addAction(a); - - menu->addSeparator(); - - a = new QAction(tr("&Quit"), this); - a->setShortcut(Qt::CTRL + Qt::Key_Q); - connect(a, SIGNAL(triggered()), this, SLOT(close())); - menu->addAction(a); + +void ChanMsgDialog::setupFileActions() +{ + QMenu *menu = new QMenu(tr("&File"), this); + menuBar()->addMenu(menu); + + QAction *a; + + a = new QAction(QIcon(":/images/textedit/filenew.png"), tr("&New"), this); + a->setShortcut(QKeySequence::New); + connect(a, SIGNAL(triggered()), this, SLOT(fileNew())); + menu->addAction(a); + + a = new QAction(QIcon(":/images/textedit/fileopen.png"), tr("&Open..."), this); + a->setShortcut(QKeySequence::Open); + connect(a, SIGNAL(triggered()), this, SLOT(fileOpen())); + menu->addAction(a); + + menu->addSeparator(); + + actionSave = a = new QAction(QIcon(":/images/textedit/filesave.png"), tr("&Save"), this); + a->setShortcut(QKeySequence::Save); + connect(a, SIGNAL(triggered()), this, SLOT(fileSave())); + a->setEnabled(false); + menu->addAction(a); + + a = new QAction(tr("Save &As..."), this); + connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs())); + menu->addAction(a); + menu->addSeparator(); + + a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("&Print..."), this); + a->setShortcut(QKeySequence::Print); + connect(a, SIGNAL(triggered()), this, SLOT(filePrint())); + menu->addAction(a); + + /*a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("Print Preview..."), this); + connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview())); + menu->addAction(a);*/ + + a = new QAction(QIcon(":/images/textedit/exportpdf.png"), tr("&Export PDF..."), this); + a->setShortcut(Qt::CTRL + Qt::Key_D); + connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf())); + menu->addAction(a); + + menu->addSeparator(); + + a = new QAction(tr("&Quit"), this); + a->setShortcut(Qt::CTRL + Qt::Key_Q); + connect(a, SIGNAL(triggered()), this, SLOT(close())); + menu->addAction(a); } -void ChanMsgDialog::setupEditActions() -{ - QMenu *menu = new QMenu(tr("&Edit"), this); - menuBar()->addMenu(menu); - - QAction *a; - a = actionUndo = new QAction(QIcon(":/images/textedit/editundo.png"), tr("&Undo"), this); - a->setShortcut(QKeySequence::Undo); - menu->addAction(a); - a = actionRedo = new QAction(QIcon(":/images/textedit/editredo.png"), tr("&Redo"), this); - a->setShortcut(QKeySequence::Redo); - menu->addAction(a); - menu->addSeparator(); - a = actionCut = new QAction(QIcon(":/images/textedit/editcut.png"), tr("Cu&t"), this); - a->setShortcut(QKeySequence::Cut); - menu->addAction(a); - a = actionCopy = new QAction(QIcon(":/images/textedit/editcopy.png"), tr("&Copy"), this); - a->setShortcut(QKeySequence::Copy); - menu->addAction(a); - a = actionPaste = new QAction(QIcon(":/images/textedit/editpaste.png"), tr("&Paste"), this); - a->setShortcut(QKeySequence::Paste); - menu->addAction(a); - actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); +void ChanMsgDialog::setupEditActions() +{ + QMenu *menu = new QMenu(tr("&Edit"), this); + menuBar()->addMenu(menu); + + QAction *a; + a = actionUndo = new QAction(QIcon(":/images/textedit/editundo.png"), tr("&Undo"), this); + a->setShortcut(QKeySequence::Undo); + menu->addAction(a); + a = actionRedo = new QAction(QIcon(":/images/textedit/editredo.png"), tr("&Redo"), this); + a->setShortcut(QKeySequence::Redo); + menu->addAction(a); + menu->addSeparator(); + a = actionCut = new QAction(QIcon(":/images/textedit/editcut.png"), tr("Cu&t"), this); + a->setShortcut(QKeySequence::Cut); + menu->addAction(a); + a = actionCopy = new QAction(QIcon(":/images/textedit/editcopy.png"), tr("&Copy"), this); + a->setShortcut(QKeySequence::Copy); + menu->addAction(a); + a = actionPaste = new QAction(QIcon(":/images/textedit/editpaste.png"), tr("&Paste"), this); + a->setShortcut(QKeySequence::Paste); + menu->addAction(a); + actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); } -void ChanMsgDialog::setupViewActions() -{ - QMenu *menu = new QMenu(tr("&View"), this); - menuBar()->addMenu(menu); - - QAction *a; - - a = new QAction(QIcon(""), tr("&Contacts Sidebar"), this); - connect(a, SIGNAL(triggered()), this, SLOT(toggleContacts())); - menu->addAction(a); - +void ChanMsgDialog::setupViewActions() +{ + QMenu *menu = new QMenu(tr("&View"), this); + menuBar()->addMenu(menu); + + QAction *a; + + a = new QAction(QIcon(""), tr("&Contacts Sidebar"), this); + connect(a, SIGNAL(triggered()), this, SLOT(toggleContacts())); + menu->addAction(a); + } -void ChanMsgDialog::setupInsertActions() -{ - QMenu *menu = new QMenu(tr("&Insert"), this); - menuBar()->addMenu(menu); - - QAction *a; - - a = new QAction(QIcon(""), tr("&Image"), this); - connect(a, SIGNAL(triggered()), this, SLOT(addImage())); - menu->addAction(a); - +void ChanMsgDialog::setupInsertActions() +{ + QMenu *menu = new QMenu(tr("&Insert"), this); + menuBar()->addMenu(menu); + + QAction *a; + + a = new QAction(QIcon(""), tr("&Image"), this); + connect(a, SIGNAL(triggered()), this, SLOT(addImage())); + menu->addAction(a); + } -void ChanMsgDialog::textBold() -{ - QTextCharFormat fmt; - fmt.setFontWeight(ui.boldbtn->isChecked() ? QFont::Bold : QFont::Normal); - mergeFormatOnWordOrSelection(fmt); -} - -void ChanMsgDialog::textUnderline() -{ - QTextCharFormat fmt; - fmt.setFontUnderline(ui.underlinebtn->isChecked()); - mergeFormatOnWordOrSelection(fmt); -} - -void ChanMsgDialog::textItalic() -{ - QTextCharFormat fmt; - fmt.setFontItalic(ui.italicbtn->isChecked()); - mergeFormatOnWordOrSelection(fmt); -} - -void ChanMsgDialog::textFamily(const QString &f) -{ - QTextCharFormat fmt; - fmt.setFontFamily(f); - mergeFormatOnWordOrSelection(fmt); -} - -void ChanMsgDialog::textSize(const QString &p) -{ - QTextCharFormat fmt; - fmt.setFontPointSize(p.toFloat()); - mergeFormatOnWordOrSelection(fmt); -} - -void ChanMsgDialog::textStyle(int styleIndex) -{ - QTextCursor cursor = ui.msgText->textCursor(); - - if (styleIndex != 0) { - QTextListFormat::Style style = QTextListFormat::ListDisc; - - switch (styleIndex) { - default: - case 1: - style = QTextListFormat::ListDisc; - break; - case 2: - style = QTextListFormat::ListCircle; - break; - case 3: - style = QTextListFormat::ListSquare; - break; - case 4: - style = QTextListFormat::ListDecimal; - break; - case 5: - style = QTextListFormat::ListLowerAlpha; - break; - case 6: - style = QTextListFormat::ListUpperAlpha; - break; - } - - cursor.beginEditBlock(); - - QTextBlockFormat blockFmt = cursor.blockFormat(); - - QTextListFormat listFmt; - - if (cursor.currentList()) { - listFmt = cursor.currentList()->format(); - } else { - listFmt.setIndent(blockFmt.indent() + 1); - blockFmt.setIndent(0); - cursor.setBlockFormat(blockFmt); - } - - listFmt.setStyle(style); - - cursor.createList(listFmt); - - cursor.endEditBlock(); - } else { - // #### - QTextBlockFormat bfmt; - bfmt.setObjectIndex(-1); - cursor.mergeBlockFormat(bfmt); - } -} - -void ChanMsgDialog::textColor() -{ - QColor col = QColorDialog::getColor(ui.msgText->textColor(), this); - if (!col.isValid()) - return; - QTextCharFormat fmt; - fmt.setForeground(col); - mergeFormatOnWordOrSelection(fmt); - colorChanged(col); -} - -void ChanMsgDialog::textAlign(QAction *a) -{ - if (a == actionAlignLeft) - ui.msgText->setAlignment(Qt::AlignLeft); - else if (a == actionAlignCenter) - ui.msgText->setAlignment(Qt::AlignHCenter); - else if (a == actionAlignRight) - ui.msgText->setAlignment(Qt::AlignRight); - else if (a == actionAlignJustify) - ui.msgText->setAlignment(Qt::AlignJustify); -} - -void ChanMsgDialog::currentCharFormatChanged(const QTextCharFormat &format) -{ - fontChanged(format.font()); - colorChanged(format.foreground().color()); -} - -void ChanMsgDialog::cursorPositionChanged() -{ - alignmentChanged(ui.msgText->alignment()); -} - -void ChanMsgDialog::mergeFormatOnWordOrSelection(const QTextCharFormat &format) -{ - QTextCursor cursor = ui.msgText->textCursor(); - if (!cursor.hasSelection()) - cursor.select(QTextCursor::WordUnderCursor); - cursor.mergeCharFormat(format); - ui.msgText->mergeCurrentCharFormat(format); -} - -void ChanMsgDialog::fontChanged(const QFont &f) -{ - ui.comboFont->setCurrentIndex(ui.comboFont->findText(QFontInfo(f).family())); - ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(f.pointSize()))); - ui.boldbtn->setChecked(f.bold()); - ui.italicbtn->setChecked(f.italic()); - ui.underlinebtn->setChecked(f.underline()); -} - -void ChanMsgDialog::colorChanged(const QColor &c) -{ - QPixmap pix(16, 16); - pix.fill(c); - ui.colorbtn->setIcon(pix); -} - -void ChanMsgDialog::alignmentChanged(Qt::Alignment a) -{ - if (a & Qt::AlignLeft) { - actionAlignLeft->setChecked(true); - } else if (a & Qt::AlignHCenter) { - actionAlignCenter->setChecked(true); - } else if (a & Qt::AlignRight) { - actionAlignRight->setChecked(true); - } else if (a & Qt::AlignJustify) { - actionAlignJustify->setChecked(true); - } +void ChanMsgDialog::textBold() +{ + QTextCharFormat fmt; + fmt.setFontWeight(ui.boldbtn->isChecked() ? QFont::Bold : QFont::Normal); + mergeFormatOnWordOrSelection(fmt); } -void ChanMsgDialog::clipboardDataChanged() -{ - actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); +void ChanMsgDialog::textUnderline() +{ + QTextCharFormat fmt; + fmt.setFontUnderline(ui.underlinebtn->isChecked()); + mergeFormatOnWordOrSelection(fmt); } -void ChanMsgDialog::fileNew() -{ - if (maybeSave()) { - ui.msgText->clear(); - //setCurrentFileName(QString()); - } -} - -void ChanMsgDialog::fileOpen() -{ - QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."), - QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); - if (!fn.isEmpty()) - load(fn); -} - -bool ChanMsgDialog::fileSave() -{ - if (fileName.isEmpty()) - return fileSaveAs(); - - QFile file(fileName); - if (!file.open(QFile::WriteOnly)) - return false; - QTextStream ts(&file); - ts.setCodec(QTextCodec::codecForName("UTF-8")); - ts << ui.msgText->document()->toHtml("UTF-8"); - ui.msgText->document()->setModified(false); - return true; -} - -bool ChanMsgDialog::fileSaveAs() -{ - QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), - QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); - if (fn.isEmpty()) - return false; - setCurrentFileName(fn); - return fileSave(); -} - -void ChanMsgDialog::filePrint() -{ -#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 TextEdit::filePrintPreview() -{ - PrintPreview *preview = new PrintPreview(textEdit->document(), this); - preview->setWindowModality(Qt::WindowModal); - preview->setAttribute(Qt::WA_DeleteOnClose); - preview->show(); -}*/ - -void ChanMsgDialog::filePrintPdf() -{ -#ifndef QT_NO_PRINTER - QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", - QString(), "*.pdf"); - if (!fileName.isEmpty()) { - if (QFileInfo(fileName).suffix().isEmpty()) - fileName.append(".pdf"); - QPrinter printer(QPrinter::HighResolution); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(fileName); - ui.msgText->document()->print(&printer); - } -#endif +void ChanMsgDialog::textItalic() +{ + QTextCharFormat fmt; + fmt.setFontItalic(ui.italicbtn->isChecked()); + mergeFormatOnWordOrSelection(fmt); } -void ChanMsgDialog::setCurrentFileName(const QString &fileName) -{ - this->fileName = fileName; - ui.msgText->document()->setModified(false); - - setWindowModified(false); +void ChanMsgDialog::textFamily(const QString &f) +{ + QTextCharFormat fmt; + fmt.setFontFamily(f); + mergeFormatOnWordOrSelection(fmt); } -bool ChanMsgDialog::load(const QString &f) -{ - if (!QFile::exists(f)) - return false; - QFile file(f); - if (!file.open(QFile::ReadOnly)) - return false; - - QByteArray data = file.readAll(); - QTextCodec *codec = Qt::codecForHtml(data); - QString str = codec->toUnicode(data); - if (Qt::mightBeRichText(str)) { - ui.msgText->setHtml(str); - } else { - str = QString::fromLocal8Bit(data); - ui.msgText->setPlainText(str); - } - - setCurrentFileName(f); - return true; -} - - -bool ChanMsgDialog::maybeSave() -{ - if (!ui.msgText->document()->isModified()) - return true; - if (fileName.startsWith(QLatin1String(":/"))) - return true; - QMessageBox::StandardButton ret; - ret = QMessageBox::warning(this, tr("Save Message"), - tr("Message has not been Sent.\n" - "Do you want to save message ?"), - QMessageBox::Save | QMessageBox::Discard - | QMessageBox::Cancel); - if (ret == QMessageBox::Save) - return fileSave(); - else if (ret == QMessageBox::Cancel) - return false; - return true; -} - - -void ChanMsgDialog::toggleContacts() -{ - ui.contactsdockWidget->setVisible(!ui.contactsdockWidget->isVisible()); +void ChanMsgDialog::textSize(const QString &p) +{ + QTextCharFormat fmt; + fmt.setFontPointSize(p.toFloat()); + mergeFormatOnWordOrSelection(fmt); } -void ChanMsgDialog::addImage() -{ - +void ChanMsgDialog::textStyle(int styleIndex) +{ + QTextCursor cursor = ui.msgText->textCursor(); + + if (styleIndex != 0) { + QTextListFormat::Style style = QTextListFormat::ListDisc; + + switch (styleIndex) { + default: + case 1: + style = QTextListFormat::ListDisc; + break; + case 2: + style = QTextListFormat::ListCircle; + break; + case 3: + style = QTextListFormat::ListSquare; + break; + case 4: + style = QTextListFormat::ListDecimal; + break; + case 5: + style = QTextListFormat::ListLowerAlpha; + break; + case 6: + style = QTextListFormat::ListUpperAlpha; + break; + } + + cursor.beginEditBlock(); + + QTextBlockFormat blockFmt = cursor.blockFormat(); + + QTextListFormat listFmt; + + if (cursor.currentList()) { + listFmt = cursor.currentList()->format(); + } else { + listFmt.setIndent(blockFmt.indent() + 1); + blockFmt.setIndent(0); + cursor.setBlockFormat(blockFmt); + } + + listFmt.setStyle(style); + + cursor.createList(listFmt); + + cursor.endEditBlock(); + } else { + // #### + QTextBlockFormat bfmt; + bfmt.setObjectIndex(-1); + cursor.mergeBlockFormat(bfmt); + } +} + +void ChanMsgDialog::textColor() +{ + QColor col = QColorDialog::getColor(ui.msgText->textColor(), this); + if (!col.isValid()) + return; + QTextCharFormat fmt; + fmt.setForeground(col); + mergeFormatOnWordOrSelection(fmt); + colorChanged(col); +} + +void ChanMsgDialog::textAlign(QAction *a) +{ + if (a == actionAlignLeft) + ui.msgText->setAlignment(Qt::AlignLeft); + else if (a == actionAlignCenter) + ui.msgText->setAlignment(Qt::AlignHCenter); + else if (a == actionAlignRight) + ui.msgText->setAlignment(Qt::AlignRight); + else if (a == actionAlignJustify) + ui.msgText->setAlignment(Qt::AlignJustify); +} + +void ChanMsgDialog::currentCharFormatChanged(const QTextCharFormat &format) +{ + fontChanged(format.font()); + colorChanged(format.foreground().color()); +} + +void ChanMsgDialog::cursorPositionChanged() +{ + alignmentChanged(ui.msgText->alignment()); +} + +void ChanMsgDialog::mergeFormatOnWordOrSelection(const QTextCharFormat &format) +{ + QTextCursor cursor = ui.msgText->textCursor(); + if (!cursor.hasSelection()) + cursor.select(QTextCursor::WordUnderCursor); + cursor.mergeCharFormat(format); + ui.msgText->mergeCurrentCharFormat(format); +} + +void ChanMsgDialog::fontChanged(const QFont &f) +{ + ui.comboFont->setCurrentIndex(ui.comboFont->findText(QFontInfo(f).family())); + ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(f.pointSize()))); + ui.boldbtn->setChecked(f.bold()); + ui.italicbtn->setChecked(f.italic()); + ui.underlinebtn->setChecked(f.underline()); +} + +void ChanMsgDialog::colorChanged(const QColor &c) +{ + QPixmap pix(16, 16); + pix.fill(c); + ui.colorbtn->setIcon(pix); +} + +void ChanMsgDialog::alignmentChanged(Qt::Alignment a) +{ + if (a & Qt::AlignLeft) { + actionAlignLeft->setChecked(true); + } else if (a & Qt::AlignHCenter) { + actionAlignCenter->setChecked(true); + } else if (a & Qt::AlignRight) { + actionAlignRight->setChecked(true); + } else if (a & Qt::AlignJustify) { + actionAlignJustify->setChecked(true); + } +} + +void ChanMsgDialog::clipboardDataChanged() +{ + actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); +} + +void ChanMsgDialog::fileNew() +{ + if (maybeSave()) { + ui.msgText->clear(); + //setCurrentFileName(QString()); + } +} + +void ChanMsgDialog::fileOpen() +{ + QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."), + QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); + if (!fn.isEmpty()) + load(fn); +} + +bool ChanMsgDialog::fileSave() +{ + if (fileName.isEmpty()) + return fileSaveAs(); + + QFile file(fileName); + if (!file.open(QFile::WriteOnly)) + return false; + QTextStream ts(&file); + ts.setCodec(QTextCodec::codecForName("UTF-8")); + ts << ui.msgText->document()->toHtml("UTF-8"); + ui.msgText->document()->setModified(false); + return true; +} + +bool ChanMsgDialog::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), + QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); + if (fn.isEmpty()) + return false; + setCurrentFileName(fn); + return fileSave(); +} + +void ChanMsgDialog::filePrint() +{ +#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 TextEdit::filePrintPreview() +{ + PrintPreview *preview = new PrintPreview(textEdit->document(), this); + preview->setWindowModality(Qt::WindowModal); + preview->setAttribute(Qt::WA_DeleteOnClose); + preview->show(); +}*/ + +void ChanMsgDialog::filePrintPdf() +{ +#ifndef QT_NO_PRINTER + QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", + QString(), "*.pdf"); + if (!fileName.isEmpty()) { + if (QFileInfo(fileName).suffix().isEmpty()) + fileName.append(".pdf"); + QPrinter printer(QPrinter::HighResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName); + ui.msgText->document()->print(&printer); + } +#endif +} + +void ChanMsgDialog::setCurrentFileName(const QString &fileName) +{ + this->fileName = fileName; + ui.msgText->document()->setModified(false); + + setWindowModified(false); +} + +bool ChanMsgDialog::load(const QString &f) +{ + if (!QFile::exists(f)) + return false; + QFile file(f); + if (!file.open(QFile::ReadOnly)) + return false; + + QByteArray data = file.readAll(); + QTextCodec *codec = Qt::codecForHtml(data); + QString str = codec->toUnicode(data); + if (Qt::mightBeRichText(str)) { + ui.msgText->setHtml(str); + } else { + str = QString::fromLocal8Bit(data); + ui.msgText->setPlainText(str); + } + + setCurrentFileName(f); + return true; +} + + +bool ChanMsgDialog::maybeSave() +{ + if (!ui.msgText->document()->isModified()) + return true; + if (fileName.startsWith(QLatin1String(":/"))) + return true; + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Save Message"), + tr("Message has not been Sent.\n" + "Do you want to save message ?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + if (ret == QMessageBox::Save) + return fileSave(); + else if (ret == QMessageBox::Cancel) + return false; + return true; +} + + +void ChanMsgDialog::toggleContacts() +{ + ui.contactsdockWidget->setVisible(!ui.contactsdockWidget->isVisible()); +} + +void ChanMsgDialog::addImage() +{ + QString fileimg = QFileDialog::getOpenFileName( this, tr( "Choose Image" ), QString(setter.value("LastDir").toString()) ,tr("Image Files supported (*.png *.jpeg *.jpg *.gif)")); - - if ( fileimg.isEmpty() ) { - return; - } - - QImage base(fileimg); - - QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/"; - setter.setValue("LastDir",pathimage); - - Create_New_Image_Tag(fileimg); + + if ( fileimg.isEmpty() ) { + return; + } + + QImage base(fileimg); + + QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/"; + setter.setValue("LastDir",pathimage); + + Create_New_Image_Tag(fileimg); } -void ChanMsgDialog::Create_New_Image_Tag( const QString urlremoteorlocal ) -{ - /*if (image_extension(urlremoteorlocal)) {*/ - QString subtext = QString("

").arg(urlremoteorlocal); - ///////////subtext.append("

Description on image.

"); - QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext); - ui.msgText->textCursor().insertFragment(fragment); - //emit statusMessage(QString("Image new :").arg(urlremoteorlocal)); - //} +void ChanMsgDialog::Create_New_Image_Tag( const QString urlremoteorlocal ) +{ + /*if (image_extension(urlremoteorlocal)) {*/ + QString subtext = QString("

").arg(urlremoteorlocal); + ///////////subtext.append("

Description on image.

"); + QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext); + ui.msgText->textCursor().insertFragment(fragment); + //emit statusMessage(QString("Image new :").arg(urlremoteorlocal)); + //} } diff --git a/retroshare-gui/src/gui/msgs/ChanMsgDialog.h b/retroshare-gui/src/gui/msgs/ChanMsgDialog.h index 1d3653c6e..95dc64e5c 100644 --- a/retroshare-gui/src/gui/msgs/ChanMsgDialog.h +++ b/retroshare-gui/src/gui/msgs/ChanMsgDialog.h @@ -17,34 +17,34 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. - ****************************************************************/ - - + ****************************************************************/ + + #ifndef _CHAN_MSG_DIALOG_H -#define _CHAN_MSG_DIALOG_H - +#define _CHAN_MSG_DIALOG_H + #include -#include +#include #include -#include +#include #include "ui_ChanMsgDialog.h" class QAction; -class QComboBox; -class QFontComboBox; -class QTextEdit; -class QTextCharFormat; - -class ChanMsgDialog : public QMainWindow -{ - Q_OBJECT - -public: - /** Default Constructor */ +class QComboBox; +class QFontComboBox; +class QTextEdit; +class QTextCharFormat; - ChanMsgDialog(bool isMsg, QWidget *parent = 0, Qt::WFlags flags = 0); - /** Default Destructor */ +class ChanMsgDialog : public QMainWindow +{ + Q_OBJECT + +public: + /** Default Constructor */ + + ChanMsgDialog(bool isMsg, QWidget *parent = 0, Qt::WFlags flags = 0); + /** Default Destructor */ void newMsg(); @@ -54,13 +54,14 @@ void insertChannelSendList(); /* for Channels */ void insertFileList(); /* for Both */ void insertTitleText(std::string title); void insertPastedText(std::string msg) ; +void insertForwardPastedText(std::string msg); void insertMsgText(std::string msg); void addRecipient(std::string id) ; void Create_New_Image_Tag( const QString urlremoteorlocal ); QSettings setter; public slots: - + /* actions to take.... */ void sendMessage(); void cancelMessage(); @@ -71,7 +72,7 @@ protected: private slots: - /** Create the context popup menu and it's submenus */ + /** Create the context popup menu and it's submenus */ void channelstreeViewCostumPopupMenu( QPoint point ); /** Defines the context menu functions*/ @@ -86,25 +87,25 @@ private slots: void toggleChannelItem( QTreeWidgetItem *item, int col ); void toggleRecommendItem( QTreeWidgetItem *item, int col ); - void fileNew(); - void fileOpen(); - bool fileSave(); - bool fileSaveAs(); + void fileNew(); + void fileOpen(); + bool fileSave(); + bool fileSaveAs(); void filePrint(); - - //void filePrintPreview(); + + //void filePrintPreview(); void filePrintPdf(); - void textBold(); - void textUnderline(); - void textItalic(); - void textFamily(const QString &f); - void textSize(const QString &p); - void textStyle(int styleIndex); - void textColor(); - void textAlign(QAction *a); - - void currentCharFormatChanged(const QTextCharFormat &format); + void textBold(); + void textUnderline(); + void textItalic(); + void textFamily(const QString &f); + void textSize(const QString &p); + void textStyle(int styleIndex); + void textColor(); + void textAlign(QAction *a); + + void currentCharFormatChanged(const QTextCharFormat &format); void cursorPositionChanged(); void clipboardDataChanged(); @@ -122,27 +123,27 @@ private: //bool image_extension( QString nametomake ); void setCurrentFileName(const QString &fileName); - void mergeFormatOnWordOrSelection(const QTextCharFormat &format); - void fontChanged(const QFont &f); - void colorChanged(const QColor &c); + void mergeFormatOnWordOrSelection(const QTextCharFormat &format); + void fontChanged(const QFont &f); + void colorChanged(const QColor &c); void alignmentChanged(Qt::Alignment a); - - /** Define the popup menus for the Context menu */ + + /** Define the popup menus for the Context menu */ QMenu* contextMnu; - /** Defines the actions for the context menu */ - QAction* deletechannelAct; + /** Defines the actions for the context menu */ + QAction* deletechannelAct; QAction* createchannelmsgAct; QAction *actionSave, - *actionAlignLeft, - *actionAlignCenter, - *actionAlignRight, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, *actionAlignJustify, - *actionUndo, - *actionRedo, - *actionCut, - *actionCopy, + *actionUndo, + *actionRedo, + *actionCut, + *actionCopy, *actionPaste; QTreeView *channelstreeView; @@ -155,11 +156,11 @@ private: QHash autoLinkTargetDictionary; bool mIsMsg; /* different behaviour for Msg or ChanMsg */ - - /** Qt Designer generated object */ - Ui::ChanMsgDialog ui; -}; - -#endif - + /** Qt Designer generated object */ + Ui::ChanMsgDialog ui; + +}; + +#endif +