redesign Create Blog Msg Publisher with html Formating features and fixed textSize formating for Message Composer

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2388 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2010-02-22 14:20:40 +00:00
parent e6678bdf9a
commit 9e584e6723
11 changed files with 1668 additions and 557 deletions

View File

@ -85,27 +85,24 @@ void BlogsMsgItem::updateItemStatic()
title = "Channel Feed: ";
title += QString::fromStdWString(ci.blogName);
titleLabel->setText(title);
subjectLabel->setText(QString::fromStdWString(cmi.subject));
//subjectLabel->setText(QString::fromStdWString(cmi.subject));
}
else
{
/* subject */
titleLabel->setText(QString::fromStdWString(cmi.subject));
subjectLabel->setText(QString::fromStdWString(cmi.msg));
/* Blog Message */
textBrowser->setHtml( QString::fromStdWString(cmi.msg));
}
msgLabel->setText(QString::fromStdWString(cmi.msg));
//msgLabel->setText(QString::fromStdWString(cmi.msg));
//msgcommentstextEdit->setHtml(QString::fromStdWString(cmi.msg));
QDateTime qtime;
qtime.setTime_t(cmi.ts);
QString timestamp = qtime.toString("dd.MMMM yyyy hh:mm:ss");
datetimelabel->setText(timestamp);
{
std::ostringstream out;
out << "(" << cmi.count << " Files)";
filelabel->setText(QString::fromStdString(out.str()));
}
std::list<FileInfo>::iterator it;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>538</width>
<height>272</height>
<width>516</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
@ -60,157 +60,8 @@ border-radius: 10px;}</string>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="5">
<widget class="QLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:11pt; font-weight:600; font-style:italic;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; color:#656565;&quot;&gt;Blog Subject&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="5" colspan="3">
<widget class="QLabel" name="datetimelabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:600; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt; color:#666666;&quot;&gt;DateTime&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="8">
<widget class="QLabel" name="subjectLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Blog Message&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>67</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="4" colspan="2">
<widget class="QPushButton" name="unsubscribeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Unsubscribe From Channel</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_delete.png</normaloff>:/images/mail_delete.png</iconset>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="clearButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove Item</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/close_normal.png</normaloff>:/images/close_normal.png</iconset>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QPushButton" name="expandButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Expand</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="filelabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QFrame" name="expandFrame">
<property name="styleSheet">
<string notr="true">QFrame#expandFrame{border: 2px solid #D3D3D3;
@ -241,22 +92,149 @@ border-radius: 10px;}</string>
</layout>
</widget>
</item>
</layout>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:11pt; font-weight:600; font-style:italic;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; color:#656565;&quot;&gt;Blog Subject&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<item row="0" column="3" colspan="2">
<widget class="QLabel" name="datetimelabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:600; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt; color:#666666;&quot;&gt;DateTime&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>200</height>
<width>288</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="expandButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Expand</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="clearButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove Item</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/close_normal.png</normaloff>:/images/close_normal.png</iconset>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="unsubscribeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Unsubscribe From Channel</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_delete.png</normaloff>:/images/mail_delete.png</iconset>
</property>
</widget>
</item>
<item row="1" column="0" colspan="5">
<widget class="QTextBrowser" name="textBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QTextBrowser#textBrowser{border: 2px solid #D3D3D3;
background-color: transparent;
border-radius: 10px;}</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>

View File

@ -19,10 +19,36 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QtGui>
//#include <QtWebKit>
#include <QAction>
#include <QApplication>
#include <QClipboard>
#include <QColorDialog>
#include <QComboBox>
#include <QFontComboBox>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QFontDatabase>
#include <QMenu>
#include <QMenuBar>
#include <QPrintDialog>
#include <QPrinter>
#include <QTextCodec>
#include <QTextEdit>
#include <QToolBar>
#include <QTextCursor>
#include <QTextDocumentWriter>
#include <QTextList>
#include <QtDebug>
#include <QCloseEvent>
#include <QMessageBox>
#include <QPrintPreviewDialog>
#include "CreateBlogMsg.h"
#include "gui/feeds/SubFileItem.h"
#include "gui/msgs/textformat.h"
#include "rsiface/rstypes.h"
#include "rsiface/rspeers.h"
@ -34,20 +60,111 @@
#include <iostream>
/** Constructor */
CreateBlogMsg::CreateBlogMsg(std::string cId)
: QDialog (NULL), mBlogId(cId) ,mCheckAttachment(true)
CreateBlogMsg::CreateBlogMsg(std::string cId ,QWidget* parent, Qt::WFlags flags)
: mBlogId(cId), QMainWindow (parent, flags) ,mCheckAttachment(true)
{
/* Invoke the Qt Designer generated object setup routine */
setupUi(this);
ui.setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancelMsg()));
connect(addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));
setupFileActions();
setupEditActions();
setupViewActions();
setupInsertActions();
setupParagraphActions();
setAcceptDrops(true);
setStartupText();
newBlogMsg();
ui.toolBar_2->addAction(ui.actionIncreasefontsize);
ui.toolBar_2->addAction(ui.actionDecreasefontsize);
ui.toolBar_2->addAction(ui.actionBlockquoute);
ui.toolBar_2->addAction(ui.actionOrderedlist);
ui.toolBar_2->addAction(ui.actionUnorderedlist);
ui.toolBar_2->addAction(ui.actionBlockquoute);
ui.toolBar_2->addAction(ui.actionCode);
ui.toolBar_2->addAction(ui.actionsplitPost);
setupTextActions();
connect(ui.actionPublish, SIGNAL(triggered()), this, SLOT(sendMsg()));
connect(ui.actionNew, SIGNAL(triggered()), this, SLOT (fileNew()));
connect(ui.addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));
connect(ui.actionIncreasefontsize, SIGNAL (triggered()), this, SLOT (fontSizeIncrease()));
connect(ui.actionDecreasefontsize, SIGNAL (triggered()), this, SLOT (fontSizeDecrease()));
connect(ui.actionBlockquoute, SIGNAL (triggered()), this, SLOT (blockQuote()));
connect(ui.actionCode, SIGNAL (triggered()), this, SLOT (toggleCode()));
connect(ui.actionsplitPost, SIGNAL (triggered()), this, SLOT (addPostSplitter()));
connect(ui.actionOrderedlist, SIGNAL (triggered()), this, SLOT (addOrderedList()));
connect(ui.actionUnorderedlist, SIGNAL (triggered()), this, SLOT (addUnorderedList()));
//connect(webView, SIGNAL(loadFinished(bool)),this, SLOT(updateTextEdit()));
connect( ui.msgEdit, SIGNAL( textChanged(const QString &)), this, SLOT(updateTextEdit()));
connect( ui.msgEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
this, SLOT(currentCharFormatChanged(QTextCharFormat)));
connect( ui.msgEdit, SIGNAL(cursorPositionChanged()),
this, SLOT(cursorPositionChanged()));
QPalette palette = QApplication::palette();
codeBackground = palette.color( QPalette::Active, QPalette::Midlight );
fontChanged(ui.msgEdit->font());
colorChanged(ui.msgEdit->textColor());
alignmentChanged(ui.msgEdit->alignment());
connect( ui.msgEdit->document(), SIGNAL(modificationChanged(bool)),
actionSave, SLOT(setEnabled(bool)));
connect( ui.msgEdit->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool)));
connect( ui.msgEdit->document(), SIGNAL(undoAvailable(bool)),
actionUndo, SLOT(setEnabled(bool)));
connect( ui.msgEdit->document(), SIGNAL(undoAvailable(bool)),
ui.actionUndo, SLOT(setEnabled(bool)));
connect( ui.msgEdit->document(), SIGNAL(redoAvailable(bool)),
actionRedo, SLOT(setEnabled(bool)));
setWindowModified( ui.msgEdit->document()->isModified());
actionSave->setEnabled( ui.msgEdit->document()->isModified());
actionUndo->setEnabled( ui.msgEdit->document()->isUndoAvailable());
ui.actionUndo->setEnabled( ui.msgEdit->document()->isUndoAvailable());
actionRedo->setEnabled( ui.msgEdit->document()->isRedoAvailable());
connect(actionUndo, SIGNAL(triggered()), ui.msgEdit, SLOT(undo()));
connect(ui.actionUndo, SIGNAL(triggered()), ui.msgEdit, SLOT(undo()));
connect(actionRedo, SIGNAL(triggered()), ui.msgEdit, SLOT(redo()));
actionCut->setEnabled(false);
actionCopy->setEnabled(false);
connect(actionCut, SIGNAL(triggered()), ui.msgEdit, SLOT(cut()));
connect(actionCopy, SIGNAL(triggered()), ui.msgEdit, SLOT(copy()));
connect(actionPaste, SIGNAL(triggered()), ui.msgEdit, SLOT(paste()));
connect(ui.msgEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
connect(ui.msgEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
#ifndef QT_NO_CLIPBOARD
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
#endif
//defaultCharFormat
defaultCharFormat = ui.msgEdit->currentCharFormat();
const QFont defaultFont = ui.msgEdit->document()->defaultFont();
defaultCharFormat.setFont( defaultFont );
defaultCharFormat.setForeground( ui.msgEdit->currentCharFormat().foreground() );
defaultCharFormat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
defaultCharFormat.setBackground( palette.color( QPalette::Active,
QPalette::Base ) );
defaultCharFormat.setProperty( TextFormat::HasCodeStyle, QVariant( false ) );
//defaultBlockFormat
defaultBlockFormat = ui.msgEdit->textCursor().blockFormat();
}
/* Dropping */
@ -261,7 +378,7 @@ void CreateBlogMsg::addAttachment(std::string hash, std::string fname, uint64_t
SubFileItem *file = new SubFileItem(hash, fname, size, flags, srcId);
mAttachments.push_back(file);
QLayout *layout = fileFrame->layout();
QLayout *layout = ui.fileFrame->layout();
layout->addWidget(file);
if (mCheckAttachment)
@ -307,7 +424,7 @@ void CreateBlogMsg::addAttachment(std::string path)
SubFileItem *file = new SubFileItem(path);
mAttachments.push_back(file);
QLayout *layout = fileFrame->layout();
QLayout *layout = ui.fileFrame->layout();
layout->addWidget(file);
if (mCheckAttachment)
@ -333,7 +450,7 @@ void CreateBlogMsg::checkAttachmentReady()
{
/*
*/
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui.actionPublish->setEnabled(false);
break;
@ -344,7 +461,7 @@ void CreateBlogMsg::checkAttachmentReady()
if (fit == mAttachments.end())
{
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
ui.actionPublish->setEnabled(true);
}
/* repeat... */
@ -374,7 +491,7 @@ void CreateBlogMsg::newBlogMsg()
return;
}
channelName->setText(QString::fromStdWString(ci.blogName));
ui.channelName->setText(QString::fromStdWString(ci.blogName));
@ -387,8 +504,8 @@ void CreateBlogMsg::sendMsg()
std::cerr << std::endl;
/* construct message bits */
std::wstring subject = subjectEdit->text().toStdWString();
std::wstring msg = msgEdit->toPlainText().toStdWString();
std::wstring subject = ui.subjectEdit->text().toStdWString();
std::wstring msg = ui.msgEdit->toHtml().toStdWString();
std::list<FileInfo> files;
@ -425,7 +542,7 @@ void CreateBlogMsg::sendMessage(std::wstring subject, std::wstring msg, std::lis
{
std::cerr << "CreateBlogMsg::sendMessage()" << std::endl;
QString name = subjectEdit->text();
QString name = ui.subjectEdit->text();
if(name.isEmpty())
{ /* error message */
@ -457,9 +574,773 @@ void CreateBlogMsg::sendMessage(std::wstring subject, std::wstring msg, std::lis
}
void CreateBlogMsg::fontSizeIncrease()
{
if ( !( ui.msgEdit->textCursor().blockFormat().hasProperty( TextFormat::HtmlHeading ) &&
ui.msgEdit->textCursor().blockFormat().intProperty( TextFormat::HtmlHeading ) ) ) {
QTextCharFormat format;
int idx = ui.msgEdit->currentCharFormat().intProperty( QTextFormat::FontSizeAdjustment );
if ( idx < 3 ) {
format.setProperty( QTextFormat::FontSizeAdjustment, QVariant( ++idx ) );
ui.msgEdit->textCursor().mergeCharFormat( format );
}
}
ui.msgEdit->setFocus( Qt::OtherFocusReason );
}
void CreateBlogMsg::fontSizeDecrease()
{
if ( !( ui.msgEdit->textCursor().blockFormat().hasProperty( TextFormat::HtmlHeading ) &&
ui.msgEdit->textCursor().blockFormat().intProperty( TextFormat::HtmlHeading ) ) ) {
QTextCharFormat format;
int idx = ui.msgEdit->currentCharFormat().intProperty( QTextFormat::FontSizeAdjustment );
if ( idx > -1 ) {
format.setProperty( QTextFormat::FontSizeAdjustment, QVariant( --idx ) );
ui.msgEdit->textCursor().mergeCharFormat( format );
}
}
ui.msgEdit->setFocus( Qt::OtherFocusReason );
}
void CreateBlogMsg::blockQuote()
{
QTextBlockFormat blockFormat = ui.msgEdit->textCursor().blockFormat();
QTextBlockFormat f;
if ( blockFormat.hasProperty( TextFormat::IsBlockQuote ) &&
blockFormat.boolProperty( TextFormat::IsBlockQuote ) ) {
f.setProperty( TextFormat::IsBlockQuote, QVariant( false ) );
f.setLeftMargin( 0 );
f.setRightMargin( 0 );
} else {
f.setProperty( TextFormat::IsBlockQuote, QVariant( true ) );
f.setLeftMargin( 40 );
f.setRightMargin( 40 );
}
ui.msgEdit->textCursor().mergeBlockFormat( f );
}
void CreateBlogMsg::toggleCode()
{
static QString preFontFamily;
QTextCharFormat charFormat = ui.msgEdit->currentCharFormat();
QTextCharFormat f;
if ( charFormat.hasProperty( TextFormat::HasCodeStyle ) &&
charFormat.boolProperty( TextFormat::HasCodeStyle ) ) {
f.setProperty( TextFormat::HasCodeStyle, QVariant( false ) );
f.setBackground( defaultCharFormat.background() );
f.setFontFamily( preFontFamily );
ui.msgEdit->textCursor().mergeCharFormat( f );
} else {
preFontFamily = ui.msgEdit->fontFamily();
f.setProperty( TextFormat::HasCodeStyle, QVariant( true ) );
f.setBackground( codeBackground );
f.setFontFamily( "Dejavu Sans Mono" );
ui.msgEdit->textCursor().mergeCharFormat( f );
}
ui.msgEdit->setFocus( Qt::OtherFocusReason );
}
void CreateBlogMsg::addPostSplitter()
{
QTextBlockFormat f = ui.msgEdit->textCursor().blockFormat();
QTextBlockFormat f1 = f;
f.setProperty( TextFormat::IsHtmlTagSign, true );
f.setProperty( QTextFormat::BlockTrailingHorizontalRulerWidth,
QTextLength( QTextLength::PercentageLength, 80 ) );
if ( ui.msgEdit->textCursor().block().text().isEmpty() ) {
ui.msgEdit->textCursor().mergeBlockFormat( f );
} else {
ui.msgEdit->textCursor().insertBlock( f );
}
ui.msgEdit->textCursor().insertBlock( f1 );
}
void CreateBlogMsg::setStartupText()
{
QString string = "<html><body><h1>HTML Previewer</h1>"
" <p>This example shows you how to use QWebView to"
" preview HTML data written in a QPlainTextEdit.</p>"
" </body></html>";
//webView->setHtml(string);
}
void CreateBlogMsg::updateTextEdit()
{
//QWebFrame *mainFrame = webView->page()->mainFrame();
QString frameText = ui.msgEdit->toHtml();
ui.plainTextEdit->setPlainText(frameText);
//QString text = plainTextEdit->toPlainText();
}
void CreateBlogMsg::textBold()
{
QTextCharFormat fmt;
fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
mergeFormatOnWordOrSelection(fmt);
}
void CreateBlogMsg::textUnderline()
{
QTextCharFormat fmt;
fmt.setFontUnderline(actionTextUnderline->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void CreateBlogMsg::textItalic()
{
QTextCharFormat fmt;
fmt.setFontItalic(actionTextItalic->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void CreateBlogMsg::textAlign(QAction *a)
{
if (a == actionAlignLeft)
ui.msgEdit->setAlignment(Qt::AlignLeft | Qt::AlignAbsolute);
else if (a == actionAlignCenter)
ui.msgEdit->setAlignment(Qt::AlignHCenter | Qt::AlignAbsolute);
else if (a == actionAlignRight)
ui.msgEdit->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);
else if (a == actionAlignJustify)
ui.msgEdit->setAlignment(Qt::AlignJustify | Qt::AlignAbsolute);
}
void CreateBlogMsg::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 CreateBlogMsg::textFamily(const QString &f)
{
QTextCharFormat fmt;
fmt.setFontFamily(f);
mergeFormatOnWordOrSelection(fmt);
}
void CreateBlogMsg::textSize(const QString &p)
{
qreal pointSize = p.toFloat();
if (p.toFloat() > 0) {
QTextCharFormat fmt;
fmt.setFontPointSize(pointSize);
mergeFormatOnWordOrSelection(fmt);
}
}
void CreateBlogMsg::textStyle(int styleIndex)
{
QTextCursor cursor = ui.msgEdit->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;
case 7:
style = QTextListFormat::ListLowerRoman;
break;
case 8:
style = QTextListFormat::ListUpperRoman;
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 CreateBlogMsg::changeFormatType(int styleIndex )
{
ui.msgEdit->setFocus( Qt::OtherFocusReason );
QTextCursor cursor = ui.msgEdit->textCursor();
//QTextBlockFormat bformat = cursor.blockFormat();
QTextBlockFormat bformat;
QTextCharFormat cformat;
switch (styleIndex) {
default:
case 0:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 0 ) );
cformat.setFontWeight( QFont::Normal );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 1:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 1 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 3 ) );
break;
case 2:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 2 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 2 ) );
break;
case 3:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 3 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 1 ) );
break;
case 4:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 4 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 5:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 5 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -1 ) );
break;
case 6:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 6 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -2 ) );
break;
}
//cformat.clearProperty( TextFormat::HasCodeStyle );
cursor.beginEditBlock();
cursor.mergeBlockFormat( bformat );
cursor.select( QTextCursor::BlockUnderCursor );
cursor.mergeCharFormat( cformat );
cursor.endEditBlock();
}
void CreateBlogMsg::textColor()
{
QColor col = QColorDialog::getColor(ui.msgEdit->textColor(), this);
if (!col.isValid())
return;
QTextCharFormat fmt;
fmt.setForeground(col);
mergeFormatOnWordOrSelection(fmt);
colorChanged(col);
}
void CreateBlogMsg::fontChanged(const QFont &f)
{
comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family()));
comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize())));
actionTextBold->setChecked(f.bold());
actionTextItalic->setChecked(f.italic());
actionTextUnderline->setChecked(f.underline());
}
void CreateBlogMsg::colorChanged(const QColor &c)
{
QPixmap pix(16, 16);
pix.fill(c);
//ui.colorbtn->setIcon(pix);
actionTextColor->setIcon(pix);
}
void CreateBlogMsg::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
QTextCursor cursor = ui.msgEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
ui.msgEdit->mergeCurrentCharFormat(format);
}
void CreateBlogMsg::currentCharFormatChanged(const QTextCharFormat &format)
{
fontChanged(format.font());
colorChanged(format.foreground().color());
}
void CreateBlogMsg::cursorPositionChanged()
{
alignmentChanged(ui.msgEdit->alignment());
}
void CreateBlogMsg::clipboardDataChanged()
{
#ifndef QT_NO_CLIPBOARD
actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty());
#endif
}
void CreateBlogMsg::addOrderedList()
{
ui.msgEdit->textCursor().createList( QTextListFormat::ListDecimal );
}
void CreateBlogMsg::addUnorderedList()
{
ui.msgEdit->textCursor().createList( QTextListFormat::ListDisc );
}
void CreateBlogMsg::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(cancelMsg()));
menu->addAction(a);
}
void CreateBlogMsg::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 CreateBlogMsg::setupViewActions()
{
QMenu *menu = new QMenu(tr("&View"), this);
menuBar()->addMenu(menu);
QAction *a;
}
void CreateBlogMsg::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 CreateBlogMsg::setupParagraphActions()
{
comboStyle = new QComboBox(ui.toolBar_2);
ui.toolBar_2->addWidget(comboStyle);
comboStyle->addItem("Paragraph");
comboStyle->addItem("Heading 1");
comboStyle->addItem("Heading 2");
comboStyle->addItem("Heading 3");
comboStyle->addItem("Heading 4");
comboStyle->addItem("Heading 5");
comboStyle->addItem("Heading 6");
connect(comboStyle, SIGNAL(activated(int)),
this, SLOT(changeFormatType(int)));
}
void CreateBlogMsg::setupTextActions()
{
QMenu *menu = new QMenu(tr("F&ormat"), this);
menuBar()->addMenu(menu);
actionTextBold = new QAction(QIcon(":/images/textedit/textbold.png"),tr("&Bold"), this);
actionTextBold->setShortcut(Qt::CTRL + Qt::Key_B);
actionTextBold->setPriority(QAction::LowPriority);
QFont bold;
bold.setBold(true);
actionTextBold->setFont(bold);
connect(actionTextBold, SIGNAL(triggered()), this, SLOT(textBold()));
ui.toolBar_2->addAction(actionTextBold);
menu->addAction(actionTextBold);
actionTextBold->setCheckable(true);
actionTextItalic = new QAction(QIcon(":/images/textedit/textitalic.png"),tr("&Italic"), this);
actionTextItalic->setPriority(QAction::LowPriority);
actionTextItalic->setShortcut(Qt::CTRL + Qt::Key_I);
QFont italic;
italic.setItalic(true);
actionTextItalic->setFont(italic);
connect(actionTextItalic, SIGNAL(triggered()), this, SLOT(textItalic()));
ui.toolBar_2->addAction(actionTextItalic);
menu->addAction(actionTextItalic);
actionTextItalic->setCheckable(true);
actionTextUnderline = new QAction(QIcon(":/images/textedit/textunder.png"),tr("&Underline"), this);
actionTextUnderline->setShortcut(Qt::CTRL + Qt::Key_U);
actionTextUnderline->setPriority(QAction::LowPriority);
QFont underline;
underline.setUnderline(true);
actionTextUnderline->setFont(underline);
connect(actionTextUnderline, SIGNAL(triggered()), this, SLOT(textUnderline()));
ui.toolBar_2->addAction(actionTextUnderline);
menu->addAction(actionTextUnderline);
actionTextUnderline->setCheckable(true);
menu->addSeparator();
QActionGroup *grp = new QActionGroup(this);
connect(grp, SIGNAL(triggered(QAction*)), this, SLOT(textAlign(QAction*)));
// Make sure the alignLeft is always left of the alignRight
if (QApplication::isLeftToRight()) {
actionAlignLeft = new QAction(QIcon(":/images/textedit/textleft.png"),tr("&Left"), grp);
actionAlignCenter = new QAction(QIcon(":/images/textedit/textcenter.png"), tr("C&enter"), grp);
actionAlignRight = new QAction(QIcon(":/images/textedit/textright.png"), tr("&Right"), grp);
} else {
actionAlignRight = new QAction(QIcon(":/images/textedit/textright.png"), tr("&Right"), grp);
actionAlignCenter = new QAction(QIcon(":/images/textedit/textcenter.png"), tr("C&enter"), grp);
actionAlignLeft = new QAction(QIcon(":/images/textedit/textleft.png"), tr("&Left"), grp);
}
actionAlignJustify = new QAction(QIcon(":/images/textedit/textjustify.png"), tr("&Justify"), grp);
actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L);
actionAlignLeft->setCheckable(true);
actionAlignLeft->setPriority(QAction::LowPriority);
actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E);
actionAlignCenter->setCheckable(true);
actionAlignCenter->setPriority(QAction::LowPriority);
actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R);
actionAlignRight->setCheckable(true);
actionAlignRight->setPriority(QAction::LowPriority);
actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J);
actionAlignJustify->setCheckable(true);
actionAlignJustify->setPriority(QAction::LowPriority);
ui.toolBar_2->addActions(grp->actions());
menu->addActions(grp->actions());
menu->addSeparator();
QPixmap pix(16, 16);
pix.fill(Qt::black);
actionTextColor = new QAction(pix, tr("&Text Color..."), this);
connect(actionTextColor, SIGNAL(triggered()), this, SLOT(textColor()));
ui.toolBar_2->addAction(actionTextColor);
menu->addAction(actionTextColor);
menu->addAction(ui.actionOrderedlist);
menu->addAction(ui.actionUnorderedlist);
menu->addAction(ui.actionBlockquoute);
/*comboStyle = new QComboBox(ui.toolBar_2);
ui.toolBar_2->addWidget(comboStyle);
comboStyle->addItem("Paragraph");
comboStyle->addItem("Heading 1");
comboStyle->addItem("Heading 2");
comboStyle->addItem("Heading 3");
comboStyle->addItem("Heading 4");
comboStyle->addItem("Heading 5");
comboStyle->addItem("Heading 6");
connect(comboStyle, SIGNAL(activated(int)),
this, SLOT(changeFormatType(int)));*/
comboFont = new QFontComboBox(ui.toolBar_2);
ui.toolBar_2->addWidget(comboFont);
connect(comboFont, SIGNAL(activated(QString)),
this, SLOT(textFamily(QString)));
comboSize = new QComboBox(ui.toolBar_2);
comboSize->setObjectName("comboSize");
ui.toolBar_2->addWidget(comboSize);
comboSize->setEditable(true);
QFontDatabase db;
foreach(int size, db.standardSizes())
comboSize->addItem(QString::number(size));
connect(comboSize, SIGNAL(activated(QString)),
this, SLOT(textSize(QString)));
comboSize->setCurrentIndex(comboSize->findText(QString::number(QApplication::font()
.pointSize())));
}
bool CreateBlogMsg::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.msgEdit->setHtml(str);
} else {
str = QString::fromLocal8Bit(data);
ui.msgEdit->setPlainText(str);
}
setCurrentFileName(f);
return true;
}
bool CreateBlogMsg::maybeSave()
{
if (!ui.msgEdit->document()->isModified())
return true;
if (fileName.startsWith(QLatin1String(":/")))
return true;
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Application"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard
| QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return fileSave();
else if (ret == QMessageBox::Cancel)
return false;
return true;
}
void CreateBlogMsg::fileNew()
{
if (maybeSave()) {
ui.msgEdit->clear();
setCurrentFileName(QString());
}
}
void CreateBlogMsg::fileOpen()
{
QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."),
QString(), tr("HTML-Files (*.htm *.html);;All Files (*)"));
if (!fn.isEmpty())
load(fn);
}
bool CreateBlogMsg::fileSave()
{
if (fileName.isEmpty())
return fileSaveAs();
QTextDocumentWriter writer(fileName);
bool success = writer.write(ui.msgEdit->document());
if (success)
ui.msgEdit->document()->setModified(false);
return success;
}
bool CreateBlogMsg::fileSaveAs()
{
QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)"));
if (fn.isEmpty())
return false;
if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) )
fn += ".odt"; // default
setCurrentFileName(fn);
return fileSave();
}
void CreateBlogMsg::filePrint()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (ui.msgEdit->textCursor().hasSelection())
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if (dlg->exec() == QDialog::Accepted) {
ui.msgEdit->print(&printer);
}
delete dlg;
#endif
}
void CreateBlogMsg::filePrintPreview()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this);
connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*)));
preview.exec();
#endif
}
void CreateBlogMsg::printPreview(QPrinter *printer)
{
#ifdef QT_NO_PRINTER
Q_UNUSED(printer);
#else
ui.msgEdit->print(printer);
#endif
}
void CreateBlogMsg::filePrintPdf()
{
#ifndef QT_NO_PRINTER
//! [0]
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.msgEdit->document()->print(&printer);
}
//! [0]
#endif
}
void CreateBlogMsg::setCurrentFileName(const QString &fileName)
{
this->fileName = fileName;
ui.msgEdit->document()->setModified(false);
QString shownName;
if (fileName.isEmpty())
shownName = "untitled.txt";
else
shownName = QFileInfo(fileName).fileName();
//setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Rich Text")));
setWindowModified(false);
}
void CreateBlogMsg::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);
}
void CreateBlogMsg::Create_New_Image_Tag( const QString urlremoteorlocal )
{
/*if (image_extension(urlremoteorlocal)) {*/
QString subtext = QString("<p><img src=\"%1\" />").arg(urlremoteorlocal);
///////////subtext.append("<br/><br/>Description on image.</p>");
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext);
ui.msgEdit->textCursor().insertFragment(fragment);
//emit statusMessage(QString("Image new :").arg(urlremoteorlocal));
//}
}

View File

@ -22,19 +22,32 @@
#ifndef _CREATEBLOGMSG_H
#define _CREATEBLOGMSG_H
#include <QMainWindow>
#include <QMap>
#include <QPointer>
#include <QObject>
#include <gui/settings/rsharesettings.h>
#include "ui_CreateBlogMsg.h"
#include <stdint.h>
class SubFileItem;
class FileInfo;
class CreateBlogMsg : public QDialog, private Ui::CreateBlogMsg
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QFontComboBox)
QT_FORWARD_DECLARE_CLASS(QTextEdit)
QT_FORWARD_DECLARE_CLASS(QTextCharFormat)
QT_FORWARD_DECLARE_CLASS(QMenu)
class CreateBlogMsg : public QMainWindow
{
Q_OBJECT
public:
/** Default Constructor */
CreateBlogMsg(std::string cId);
CreateBlogMsg(std::string cId, QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default Destructor */
void addAttachment(std::string path);
@ -44,6 +57,9 @@ public:
void newBlogMsg();
QPixmap picture;
QSettings setter;
void Create_New_Image_Tag( const QString urlremoteorlocal );
protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
@ -55,9 +71,64 @@ private slots:
void cancelMsg();
void sendMsg();
void addImage();
void fontSizeIncrease();
void fontSizeDecrease();
void blockQuote();
void toggleCode();
void addPostSplitter();
void setStartupText();
void updateTextEdit();
void fileNew();
void fileOpen();
bool fileSave();
bool fileSaveAs();
void filePrint();
void filePrintPreview();
void filePrintPdf();
void printPreview(QPrinter *);
void textBold();
void textUnderline();
void textItalic();
void textFamily(const QString &f);
void textSize(const QString &p);
void textStyle(int styleIndex);
void changeFormatType(int styleIndex );
void textColor();
void textAlign(QAction *a);
void addOrderedList();
void addUnorderedList();
void currentCharFormatChanged(const QTextCharFormat &format);
void cursorPositionChanged();
void clipboardDataChanged();
private:
void setupFileActions();
void setupEditActions();
void setupViewActions();
void setupInsertActions();
void setupParagraphActions();
void setupTextActions();
void setCurrentFileName(const QString &fileName);
bool load(const QString &f);
bool maybeSave();
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
void colorChanged(const QColor &c);
void alignmentChanged(Qt::Alignment a);
void parseRsFileListAttachments(std::string attachList);
@ -68,6 +139,36 @@ private:
std::list<SubFileItem *> mAttachments;
bool mCheckAttachment;
QAction *actionSave,
*actionTextBold,
*actionTextUnderline,
*actionTextItalic,
*actionTextColor,
*actionAlignLeft,
*actionAlignCenter,
*actionAlignRight,
*actionAlignJustify,
*actionUndo,
*actionRedo,
*actionCut,
*actionCopy,
*actionPaste;
QComboBox *comboStyle;
QFontComboBox *comboFont;
QComboBox *comboSize;
QString fileName;
QColor codeBackground;
QTextCharFormat defaultCharFormat;
QTextBlockFormat defaultBlockFormat;
QTextCharFormat lastCharFormat;
QTextBlockFormat lastBlockFormat;
/** Qt Designer generated object */
Ui::CreateBlogMsg ui;
};

View File

@ -1,18 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateBlogMsg</class>
<widget class="QDialog" name="CreateBlogMsg">
<widget class="QMainWindow" name="CreateBlogMsg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<height>464</height>
<width>666</width>
<height>515</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>New Blog Post</string>
</property>
@ -20,72 +17,26 @@
<iconset resource="../images.qrc">
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<property name="styleSheet">
<string notr="true">QToolBar#toolBar{background-image: url(:/images/connect/connectFriendBanner.png);
}
QToolButton {
color: white;
}
QToolBar#toolBar_2{
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #FEFEFE, stop:1 #E8E8E8);
border: 1px solid #CCCCCC;}</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>64</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QFrame#frame{background-image: url(:/images/connect/connectFriendBanner.png);}
</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/hi48-app-kblogger.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:26pt; color:#ffffff;&quot;&gt;New Blog Post&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@ -94,8 +45,17 @@ p, li { white-space: pre-wrap; }
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
@ -104,7 +64,7 @@ p, li { white-space: pre-wrap; }
<string>Blog Post</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0" colspan="2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_8">
@ -131,14 +91,24 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget_2">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Visual Editor</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Blog Message</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
@ -157,7 +127,7 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<item row="1" column="0">
<widget class="QTextEdit" name="msgEdit"/>
</item>
</layout>
@ -165,6 +135,20 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<widget class="QWidget" name="tabHtml">
<attribute name="title">
<string>Html Editor</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="0">
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="icon">
<iconset resource="../images.qrc">
@ -277,8 +261,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>582</width>
<height>282</height>
<width>639</width>
<height>341</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -334,27 +318,191 @@ background: white;}</string>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionPublish"/>
<addaction name="separator"/>
<addaction name="actionNew"/>
</widget>
<widget class="QToolBar" name="toolBar_2">
<property name="windowTitle">
<string>toolBar_2</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="actionUndo"/>
</widget>
<action name="actionBlockquoute">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/hi22-action-format-text-blockquote.png</normaloff>:/images/textedit/hi22-action-format-text-blockquote.png</iconset>
</property>
<property name="text">
<string>blockquoute</string>
</property>
</action>
<action name="actionIncreasefontsize">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/format_font_size_more.png</normaloff>:/images/textedit/format_font_size_more.png</iconset>
</property>
<property name="text">
<string>Increase font Size</string>
</property>
</action>
<action name="actionDecreasefontsize">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/format_font_size_less.png</normaloff>:/images/textedit/format_font_size_less.png</iconset>
</property>
<property name="text">
<string>Decrease font size</string>
</property>
</action>
<action name="actionBold">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/textbold.png</normaloff>:/images/textedit/textbold.png</iconset>
</property>
<property name="text">
<string>Bold</string>
</property>
</action>
<action name="actionUnderline">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/textunder.png</normaloff>:/images/textedit/textunder.png</iconset>
</property>
<property name="text">
<string>Underline</string>
</property>
</action>
<action name="actionItalic">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/textitalic.png</normaloff>:/images/textedit/textitalic.png</iconset>
</property>
<property name="text">
<string>Italic</string>
</property>
</action>
<action name="actionPublish">
<property name="text">
<string>Publish</string>
</property>
</action>
<action name="actionNew">
<property name="text">
<string>New</string>
</property>
</action>
<action name="actionCode">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/hi22-action-format-text-code.png</normaloff>:/images/textedit/hi22-action-format-text-code.png</iconset>
</property>
<property name="text">
<string>Code</string>
</property>
</action>
<action name="actionsplitPost">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/hi22-action-insert-more-mark.png</normaloff>:/images/textedit/hi22-action-insert-more-mark.png</iconset>
</property>
<property name="text">
<string>splitPost</string>
</property>
</action>
<action name="actionOrderedlist">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/format-list-ordered.png</normaloff>:/images/textedit/format-list-ordered.png</iconset>
</property>
<property name="text">
<string>Ordered List</string>
</property>
</action>
<action name="actionUnorderedlist">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/format-list-unordered.png</normaloff>:/images/textedit/format-list-unordered.png</iconset>
</property>
<property name="text">
<string>Unordered List</string>
</property>
</action>
<action name="actionClipboard">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/editcut.png</normaloff>:/images/textedit/editcut.png</iconset>
</property>
<property name="text">
<string>Clipboard</string>
</property>
</action>
<action name="actionUndo">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/textedit/editundo.png</normaloff>:/images/textedit/editundo.png</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
</action>
</widget>
<resources>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -351,6 +351,9 @@
<file>images/textedit/fileopen.png</file>
<file>images/textedit/fileprint.png</file>
<file>images/textedit/filesave.png</file>
<file>images/textedit/format-text-color.png</file>
<file>images/textedit/format-list-ordered.png</file>
<file>images/textedit/format-list-unordered.png</file>
<file>images/textedit/zoomin.png</file>
<file>images/textedit/zoomout.png</file>
<file>images/textedit/format_font_size_more.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

View File

@ -783,10 +783,13 @@ void ChanMsgDialog::textFamily(const QString &f)
void ChanMsgDialog::textSize(const QString &p)
{
qreal pointSize = p.toFloat();
if (p.toFloat() > 0) {
QTextCharFormat fmt;
fmt.setFontPointSize(p.toFloat());
fmt.setFontPointSize(pointSize);
mergeFormatOnWordOrSelection(fmt);
}
}
void ChanMsgDialog::textStyle(int styleIndex)
{