[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/blogilo/src
From: Mehrdad Momeny <mehrdad.momeny () gmail ! com>
Date: 2010-11-06 15:55:45
Message-ID: 20101106155545.89A2EAC89B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1193631 by momeny:
BilboEditor merged in PostEntry
M +0 -1 CMakeLists.txt
D composer/bilboeditor.cpp
D composer/bilboeditor.h
M +144 -28 postentry.cpp
M +30 -3 postentry.h
--- trunk/KDE/kdepim/blogilo/src/CMakeLists.txt #1193630:1193631
@@ -23,7 +23,6 @@
syncuploader.cpp
composer/htmleditor.cpp
composer/stylegetter.cpp
- composer/bilboeditor.cpp
composer/dialogs/addeditlink.cpp
composer/dialogs/addmediadialog.cpp
composer/dialogs/addeditimage.cpp
--- trunk/KDE/kdepim/blogilo/src/postentry.cpp #1193630:1193631
@@ -23,11 +23,17 @@
*/
#include "postentry.h"
+
+#ifdef WIN32
+#include "composer/bilbobrowser_win.h"
+#else
+#include "composer/bilbobrowser.h"
+#endif
+
#include <kdebug.h>
#include <klocalizedstring.h>
#include <klineedit.h>
#include <KMessageBox>
-#include "composer/bilboeditor.h"
#include "bilbomedia.h"
#include "backend.h"
#include "dbman.h"
@@ -42,14 +48,19 @@
#include <QTimer>
#include <qlayout.h>
#include "composer/texteditor.h"
+#include "composer/htmleditor.h"
+#include <ktexteditor/view.h>
+#include <ktexteditor/document.h>
+#include <QHBoxLayout>
+#include <KTabWidget>
+
#define MINUTE 60000
class PostEntry::Private
{
public:
QProgressBar *progress;
- BilboEditor *editPostWidget;
QGridLayout *gridLayout;
QHBoxLayout *horizontalLayout;
QLabel *labelTitle;
@@ -64,6 +75,18 @@
bool isNewPost;
// bool mIsModified;
bool isPostContentModified;
+
+
+ KTabWidget *tabWidget;
+ QWidget *tabVisual;
+ QWidget *tabHtml;
+ QWidget *tabPreview;
+
+ TextEditor *wysiwygEditor;
+ KTextEditor::View *htmlEditor;
+ BilboBrowser *previewer;
+
+ int prev_index;
};
PostEntry::PostEntry( QWidget *parent )
@@ -71,9 +94,10 @@
{
kDebug();
createUi();
- d->editPostWidget = new BilboEditor( this );
-// editPostWidget->setMediaList( &mMediaList );
- layout()->addWidget( d->editPostWidget );
+ connect( d->wysiwygEditor, SIGNAL( textChanged() ), this, SIGNAL( textChanged() ) );
+ connect( d->htmlEditor->document(), SIGNAL( textChanged( KTextEditor::Document * ) ),
+ this, SIGNAL( textChanged() ) );
+ layout()->addWidget( d->tabWidget );
d->mTimer = new QTimer(this);
d->mTimer->start(Settings::autosaveInterval() * MINUTE);
connect( d->mTimer, SIGNAL(timeout()), this, SLOT( saveTemporary() ) );
@@ -81,11 +105,7 @@
d->mCurrentPostBlogId = -1;
d->mNumOfFilesToBeUploaded = 0;
d->isPostContentModified = false;
- connect( d->editPostWidget, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
-// connect( txtTitle, SIGNAL(textChanged(QString)), this, SLOT(slotPostModified()) );
- connect( d->editPostWidget, SIGNAL( sigShowStatusMessage( const QString&, bool ) ),
- this, SIGNAL( showStatusMessage( const QString&, bool ) ) );
- connect( d->editPostWidget, SIGNAL( sigBusy( bool ) ), this, SIGNAL( sigBusy( bool ) ) );
+ connect( this, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
}
void PostEntry::aboutToQuit()
@@ -106,6 +126,38 @@
void PostEntry::createUi()
{
+
+ d->tabWidget = new KTabWidget(this);
+ d->tabVisual = new QWidget( d->tabWidget );
+ d->tabHtml = new QWidget( d->tabWidget );
+ d->tabPreview = new QWidget( d->tabWidget );
+ d->tabWidget->addTab( d->tabVisual, i18nc( "Software", "Visual Editor" ) );
+ d->tabWidget->addTab( d->tabHtml, i18nc( "Software", "Html Editor" ) );
+ d->tabWidget->addTab( d->tabPreview, i18nc( "preview of the edited post", "Post Preview" ) );
+ connect( d->tabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( slotSyncEditors( int ) ) );
+ d->prev_index = 0;
+
+ /// WYSIWYG Editor:
+ d->wysiwygEditor = new TextEditor( d->tabVisual );
+ QVBoxLayout *vLayout = new QVBoxLayout( d->tabVisual );
+ vLayout->addWidget( d->wysiwygEditor );
+
+ ///htmlEditor:
+ d->htmlEditor = HtmlEditor::self()->createView( d->tabHtml );
+ QGridLayout *hLayout = new QGridLayout( d->tabHtml );
+ hLayout->addWidget( d->htmlEditor );
+
+ ///previewer:
+ d->previewer = new BilboBrowser( d->tabPreview );
+ QGridLayout *gLayout = new QGridLayout( d->tabPreview );
+ gLayout->addWidget( d->previewer );
+
+ connect( d->previewer, SIGNAL( sigSetBlogStyle() ), this, SLOT(
+ slotSetPostPreview() ) );
+
+
+ d->tabWidget->setCurrentIndex( 0 );
+
this->resize( 626, 307 );
d->gridLayout = new QGridLayout( this );
@@ -126,10 +178,67 @@
}
+void PostEntry::slotSyncEditors(int index)
+{
+ kDebug();
+
+ if ( index == 0 ) {
+ if ( d->prev_index == 2 ) {
+ d->previewer->stop();
+ goto SyncEnd;
+ }//An else clause can do the job of goto, No? -Mehrdad :D
+ d->wysiwygEditor->setHtmlContent(d->htmlEditor->document()->text());
+ d->wysiwygEditor->setFocus();
+ d->wysiwygEditor->startEditing();
+ } else if ( index == 1 ) {
+ if ( d->prev_index == 2 ) {
+ d->previewer->stop();
+ goto SyncEnd;
+ }
+ d->htmlEditor->document()->setText( d->wysiwygEditor->htmlContent() );
+ d->htmlEditor->setFocus();
+ } else {
+ if ( d->prev_index == 1 ) {
+ d->wysiwygEditor->setHtmlContent(d->htmlEditor->document()->text());
+ } else {
+ d->htmlEditor->document()->setText( d->wysiwygEditor->htmlContent() );
+ }
+ d->previewer->setHtml( d->txtTitle->text(), d->htmlEditor->document()->text() );
+ }
+SyncEnd:
+ d->prev_index = index;
+}
+
+void PostEntry::slotSetPostPreview()
+{
+ if ( d->tabWidget->currentIndex() == 2 ) {
+ d->previewer->setHtml( d->txtTitle->text(), d->htmlEditor->document()->text() );
+ }
+}
+
+QString PostEntry::htmlContent()
+{
+
+ if ( d->tabWidget->currentIndex() == 0 ) {
+ d->htmlEditor->document()->setText( d->wysiwygEditor->htmlContent() );
+ }
+ return d->wysiwygEditor->htmlContent();
+}
+
+QString PostEntry::plainTextContent()
+{
+ return d->wysiwygEditor->plainTextContent();
+}
+
+void PostEntry::setHtmlContent(const QString& content)
+{
+ d->wysiwygEditor->setHtmlContent(content);
+ d->htmlEditor->document()->setText( content );
+}
+
void PostEntry::slotTitleChanged( const QString& title )
{
d->mCurrentPost.setTitle( title );
- d->editPostWidget->setCurrentTitle( title );
Q_EMIT sigTitleChanged( title );
}
@@ -143,7 +252,6 @@
kDebug();
d->txtTitle->setText( title );
d->mCurrentPost.setTitle( title );
- d->editPostWidget->setCurrentTitle( title );
}
void PostEntry::setPostBody( const QString & content, const QString &additionalContent )
@@ -160,9 +268,9 @@
// body = "<p></p>";//This is because of Bug #387578
// }
d->mCurrentPost.setContent( body );
- d->editPostWidget->setHtmlContent( body );
+ setHtmlContent( body );
d->isPostContentModified = false;
- connect( d->editPostWidget, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
+ connect( this, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
// connect( txtTitle, SIGNAL(textChanged(QString)), this, SLOT(slotPostModified()) );
}
@@ -184,10 +292,10 @@
{
if( d->isPostContentModified ) {
kDebug();
- const QString& str = d->editPostWidget->htmlContent();
+ const QString& str = htmlContent();
d->mCurrentPost.setContent( str );
d->isPostContentModified = false;
- connect( d->editPostWidget, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
+ connect( this, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
}
}
@@ -200,8 +308,6 @@
void PostEntry::setCurrentPost( const BilboPost &post )
{
kDebug();
-// if(mCurrentPost)
-// delete mCurrentPost;
d->mCurrentPost = BilboPost( post );
// kDebug()<<"postId: "<<mCurrentPost.postId();
this->setPostBody( d->mCurrentPost.content(), d->mCurrentPost.additionalContent() );
@@ -216,7 +322,7 @@
void PostEntry::setDefaultLayoutDirection( Qt::LayoutDirection direction )
{
kDebug();
- d->editPostWidget->setLayoutDirection( direction );
+ d->tabWidget->setLayoutDirection( direction );
d->txtTitle->setLayoutDirection( direction );
}
@@ -226,6 +332,16 @@
delete d;
}
+QList< BilboMedia* > PostEntry::localImages()
+{
+ return d->wysiwygEditor->getLocalImages();
+}
+
+void PostEntry::replaceImageSrc(const QString& src, const QString& dest)
+{
+ d->wysiwygEditor->replaceImageSrc(src, dest);
+}
+
bool PostEntry::uploadMediaFiles( Backend *backend )
{
kDebug();
@@ -235,18 +351,18 @@
localBackend = true;
backend = new Backend( d->mCurrentPostBlogId, this );
}
- QList<BilboMedia*> localImages = d->editPostWidget->localImages();
- if( localImages.size()>0 ) {
+ QList<BilboMedia*> lImages = localImages();
+ if( lImages.size()>0 ) {
d->progress = new QProgressBar( this );
layout()->addWidget( d->progress );
d->progress->setRange( 0, 0 );
- QList<BilboMedia*>::iterator it = localImages.begin();
- QList<BilboMedia*>::iterator endIt = localImages.end();
+ QList<BilboMedia*>::iterator it = lImages.begin();
+ QList<BilboMedia*>::iterator endIt = lImages.end();
for ( ; it != endIt; ++it ) {
BilboMedia *media = (*it);
SyncUploader *uploader = new SyncUploader(this);
if( uploader->uploadMedia( backend, media ) ){
- d->editPostWidget->replaceImageSrc( media->localUrl().url(),
+ replaceImageSrc( media->localUrl().url(),
media->remoteUrl().url());
} else {
QString err = i18n( "Uploading the media file %1 failed.\n%2",
@@ -257,7 +373,7 @@
}
uploader->deleteLater();
}
- d->mCurrentPost.setContent( d->editPostWidget->htmlContent() );
+ d->mCurrentPost.setContent( htmlContent() );
}
if(localBackend)
backend->deleteLater();
@@ -379,7 +495,7 @@
void PostEntry::saveTemporary( bool force )
{
- if( d->isPostContentModified || ( !d->editPostWidget->plainTextContent().isEmpty() && force ) ) {
+ if( d->isPostContentModified || ( !plainTextContent().isEmpty() && force ) ) {
d->mCurrentPost.setId( DBMan::self()->saveTempEntry( *currentPost(), d->mCurrentPostBlogId) );
emit postSavedTemporary();
kDebug()<<"Temporary saved";
@@ -389,9 +505,9 @@
void PostEntry::slotPostModified()
{
kDebug();
- disconnect( d->editPostWidget, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
+ disconnect( this, SIGNAL(textChanged()), this, SLOT(slotPostModified()) );
// disconnect( txtTitle, SIGNAL(textChanged(QString)), this, SLOT(slotPostModified()) );
- emit postModified();
+// emit postModified();
d->isPostContentModified = true;
}
--- trunk/KDE/kdepim/blogilo/src/postentry.h #1193630:1193631
@@ -28,7 +28,6 @@
#include <QFrame>
#include "bilbopost.h"
-class BilboEditor;
class QGridLayout;
class QLabel;
class QHBoxLayout;
@@ -90,9 +89,9 @@
void postPublishingDone( bool isError, const QString &customMessage );
/**
- * This signal is emitted when the post contents (Title or content) is modified!
+ * This signal is emitted when the content of VisualEditor or HtmlEditor changes.
*/
- void postModified();
+ void textChanged();
/**
* This signal is emitted when the post is saved temporarily!
@@ -128,6 +127,34 @@
void saveTemporary( bool force=false );
void slotPostModified();
+ /*!
+ * Sets the content of the current tab as other tabs' contents, to apply recent
+ * changes. this function executes each time the user switches between tabs.
+ */
+ void slotSyncEditors( int index );
+
+ void slotSetPostPreview();
+
+protected:
+ /**
+ * @brief Returns the editor current text in html format
+ * Synchronizes HtmlEditor and editor tabs, by sending content of the current one to another.
+ * then copies the content of HtmlEditor into the variable mHtmlContent, and returns it.
+ * @return an String which contains html text
+ */
+ QString htmlContent();
+
+ QString plainTextContent();
+
+ /**
+ * Sets the given string as the HtmlEditor and VisualEditor content.
+ * @param content
+ */
+ void setHtmlContent( const QString &content );
+
+ QList <BilboMedia*> localImages();
+ void replaceImageSrc(const QString& src, const QString& dest);
+
private:
void createUi();
void setCurrentPostFromEditor();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic