[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-10-29 16:34:05
Message-ID: 20101029163405.3FAFDAC899 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1191123 by momeny:
Add a link to editor + some other code clean up
M +2 -2 CMakeLists.txt
M +1 -102 composer/bilboeditor.h
M +73 -52 composer/dialogs/addeditlink.cpp
M +14 -8 composer/dialogs/addeditlink.h
M +54 -3 composer/texteditor/texteditor.cpp
M +2 -2 composer/texteditor/texteditor.h
--- trunk/KDE/kdepim/blogilo/src/CMakeLists.txt #1191122:1191123
@@ -100,9 +100,9 @@
kde4_add_executable( blogilo ${blogilo_SRCS})
IF(WIN32)
-target_link_libraries( blogilo ${KDE4_KDEUI_LIBS} ${QT_QTSQL_LIBRARY} \
${KDE4_KTEXTEDITOR_LIBS} ${QT_QTWEBKIT_LIBRARY} ${KDEPIMLIBS_KBLOG_LIBS} \
htmlconvertors ) +target_link_libraries( blogilo ${KDE4_KDEUI_LIBS} \
${QT_QTSQL_LIBRARY} ${KDE4_KTEXTEDITOR_LIBS} ${QT_QTWEBKIT_LIBRARY} \
${KDE4_KDEWEBKIT_LIBRARY} ${KDEPIMLIBS_KBLOG_LIBS} htmlconvertors ) ELSE(WIN32)
-target_link_libraries( blogilo ${KDE4_KDEUI_LIBS} ${QT_QTSQL_LIBRARY} \
${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KHTML_LIBS} ${QT_QTWEBKIT_LIBRARY} \
${KDEPIMLIBS_KBLOG_LIBS} htmlconvertors ) +target_link_libraries( blogilo \
${KDE4_KDEUI_LIBS} ${QT_QTSQL_LIBRARY} ${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KHTML_LIBS} \
${QT_QTWEBKIT_LIBRARY} ${KDE4_KDEWEBKIT_LIBRARY} ${KDEPIMLIBS_KBLOG_LIBS} \
htmlconvertors ) ENDIF(WIN32)
--- trunk/KDE/kdepim/blogilo/src/composer/bilboeditor.h #1191122:1191123
@@ -148,52 +148,8 @@
// void sltSyncSpellCheckingButton( bool check );
-// void sltSetTextBold( bool bold );
/*!
- Changes the current text font into Courier fontfamily, to represent code style.
- or if text font already be in code style, uses the fontfamily it had before.
- */
-// void sltToggleCode();
-
- /**
- * Changes the current paragraph format into Heading type or simple pargraph
- * type, according to the given parameter.
- *
- * @param index is the index of the selected format type in the related
- * combobox in toolbar.
- */
-// void sltChangeFormatType( const QString& text );
- /*!
- Increments font size by one degree.
- there are five predefined values for font size: "small", "medium", "large",
- * "x-large", "xx-large". Bilboeditor uses "medium" as default font size.
- */
-// void sltFontSizeIncrease();
-
- /*!
- Decrements font size by one degree.
- there are five predefined values for font size: "small", "medium", "large",
- * "x-large", "xx-large". Bilboeditor uses "medium" as default font size.
- */
-// void sltFontSizeDecrease();
-
- /*!
- Changes Alignment of current paragraph into Right Alignment.
- */
-// void sltAlignRight();
-
- /*!
- Changes Alignment of current paragraph into Left Alignment.
- */
-// void sltAlignLeft();
-
- /*!
- Switches Layout Direction of current paragraph between RightToLeft and \
LeftToRight Directions.
- */
-// void sltChangeLayoutDirection();
-
- /*!
Opens a dialog to set link address. if cursor has selection and it is a link
* itself, the link address is shown in the dialog to edit.
*/
@@ -210,18 +166,6 @@
*/
void sltRemoveLink();
- /*!
- Changes the forground color of current text.
- */
-// void sltSelectColor();
-
- /*!
- Changes all properties of current text format into default, except Anchor,
- * AnchorName and AnchorHref properties.
- \sa defaultCharFormat
- */
-// void sltRemoveFormatting();
-
/**
* Creates an instance of AddImageDialog class,and opens it, to select an image.
*/
@@ -250,17 +194,10 @@
// void sltMediaTypeFound( BilboMedia *media );
-// void sltAddOrderedList();
-
-// void sltAddUnorderedList();
-
// void sltToggleBlockQuote();
void sltAddPostSplitter();
-// void slotCurrentCharFormantChanged(const QTextCharFormat &);
-// void slotCurrentBlockFormatChanged(const QTextBlockFormat &);
-
/*!
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.
@@ -298,54 +235,16 @@
QWidget *tabPreview;
TextEditor *editor;
-// QPlainTextEdit *htmlEditor;
KTextEditor::View *htmlEditor;
-// QWebView *preview;
-// KHTMLPart *browserPart;
+
BilboBrowser *preview;
KToolBar *barVisual;
-// KListWidget *lstMediaFiles;
-// KPushButton *btnGetStyle;
-
- KAction *actBold;
- KAction *actItalic;
- KAction *actUnderline;
- KAction *actStrikeout;
- KAction *actCode;
- KAction *actFontIncrease;
- KAction *actFontDecrease;
- KAction *actNewParagraph;
- KAction *actAlignRight;
- KAction *actAlignLeft;
- KAction *actAlignCenter;
- KAction *actJustify;
- KAction *actRightToLeft;
- KAction *actAddLink;
- KAction *actRemoveLink;
- KAction *actRemoveFormatting;
- KAction *actColorSelect;
- KAction *actAddImage;
-// KAction *actAddMedia;
- KAction *actOrderedList;
- KAction *actUnorderedList;
- KAction *actBlockQuote;
- KAction *actSplitPost;
- KAction *actCheckSpelling;
- KSelectAction *actFormatType;
-
-// QProgressBar *previewProgress;
-// KStatusBar *previewStatus;
-
-// QString *mHtmlContent;
-
AddEditLink *linkDialog;
QTextCharFormat defaultCharFormat;
QTextBlockFormat defaultBlockFormat;
-// QTextCharFormat lastCharFormat;
-// QTextBlockFormat lastBlockFormat;
QMap <QString, BilboMedia*> *mMediaList;
--- trunk/KDE/kdepim/blogilo/src/composer/dialogs/addeditlink.cpp #1191122:1191123
@@ -24,94 +24,115 @@
#include "addeditlink.h"
#include "settings.h"
+#include "ui_addeditlinkbase.h"
// KConfigGroup AddEditLink::links( KGlobal::config(), \
QString::fromLatin1("LinksCache") );
+class AddEditLink::Private
+{
+public:
+ Link result;
+ KConfigGroup *confGroup;
+ Ui::AddEditLinkBase ui;
+};
AddEditLink::AddEditLink( QWidget *parent )
- : KDialog( parent )
+ : KDialog( parent ), d(new Private)
{
- setAttribute(Qt::WA_DeleteOnClose);
+ initUi();
+}
+
+AddEditLink::AddEditLink(const QString& address, const QString& title, const \
QString& target, + QWidget* parent): KDialog(parent), d(new \
Private) +{
+ if ( address.isEmpty() ) {
+ d->ui.txtAddress->insertUrl(0, QString());
+ d->ui.txtAddress->setCurrentIndex(0);
+ this->setWindowTitle( i18nc( "verb, to insert a link into the text", "Add \
Link" ) ); + } else {
+ d->ui.txtAddress->setCurrentItem( address, true );
+ this->setWindowTitle( i18nc( "verb, to modify an existing link", "Edit Link" \
) ); + }
+ if ( !title.isEmpty() ) {
+ d->ui.txtTitle->setText( title );
+ }
+ if ( !target.isEmpty() ) {
+ if ( target == "_self" ) {
+ d->ui.comboTarget->setCurrentIndex( 1 );
+ } else if ( target == "_blank" ) {
+ d->ui.comboTarget->setCurrentIndex( 2 );
+ }
+ }
+ initUi();
+}
+
+AddEditLink::~AddEditLink()
+{
+ d->confGroup->writeEntry( "Size", size() );
+ d->confGroup->sync();
+ delete d->confGroup;
+}
+
+void AddEditLink::initUi()
+{
QWidget *dialog = new QWidget( this );
- ui.setupUi( dialog );
- ui.btnClear->setIcon(KIcon("edit-clear"));
+ d->ui.setupUi( dialog );
+ d->ui.btnClear->setIcon(KIcon("edit-clear"));
this->setMainWidget( dialog );
this->resize( dialog->width(), dialog->height() );
- confGroup = new KConfigGroup( KGlobal::config(), \
QString::fromLatin1("AddEditLinkDialog") );
- QStringList linksList = confGroup->readEntry("LinksCache", QStringList());
- ui.txtAddress->addItems(linksList);
- KCompletion *comp = ui.txtAddress->completionObject( true );
+ d->confGroup = new KConfigGroup( KGlobal::config(), \
QString::fromLatin1("AddEditLinkDialog") ); + QStringList linksList = \
d->confGroup->readEntry("LinksCache", QStringList()); + \
linksList.removeDuplicates(); + d->ui.txtAddress->addItems(linksList);
+ KCompletion *comp = d->ui.txtAddress->completionObject( true );
comp->setItems(linksList);
- ui.txtAddress->setCompletionMode(KGlobalSettings::CompletionPopupAuto);
+ d->ui.txtAddress->setCompletionMode(KGlobalSettings::CompletionPopupAuto);
- ui.txtAddress->setFocus();
- resize( confGroup->readEntry("Size", this->size()) );
- connect(ui.btnClear, SIGNAL(clicked(bool)), SLOT(slotClearLinkCache()) );
+ d->ui.txtAddress->setFocus();
+ resize( d->confGroup->readEntry("Size", this->size()) );
+ connect(d->ui.btnClear, SIGNAL(clicked(bool)), SLOT(slotClearLinkCache()) );
}
-AddEditLink::~AddEditLink()
+Link& AddEditLink::result() const
{
- confGroup->writeEntry( "Size", size() );
- confGroup->sync();
- delete confGroup;
+ return d->result;
}
void AddEditLink::slotButtonClicked( int button )
{
if(button == KDialog::Ok) {
- QString link = ui.txtAddress->currentText();
+ QString link = d->ui.txtAddress->currentText();
if ( link.isEmpty() )
return;
QString linkTarget;
- if ( ui.comboTarget->currentIndex() == 1 ) {
+ if ( d->ui.comboTarget->currentIndex() == 1 ) {
linkTarget = "_self";
- } else if ( ui.comboTarget->currentIndex() == 2 ) {
+ } else if ( d->ui.comboTarget->currentIndex() == 2 ) {
linkTarget = "_blank";
}
const QString target = linkTarget;
if( Settings::urlCachingEnabled() ) {
- QStringList linksList = confGroup->readEntry("LinksCache", \
QStringList()); + QStringList linksList = \
d->confGroup->readEntry("LinksCache", QStringList()); linksList.append(link);
- confGroup->writeEntry("LinksCache", linksList );
- confGroup->sync();
+ d->confGroup->writeEntry("LinksCache", linksList );
+ d->confGroup->sync();
}
- emit addLink( link, target, ui.txtTitle->text() );
+ d->result.address = link;
+ d->result.target = target;
+ d->result.title = d->ui.txtTitle->text();
accept();
} else
KDialog::slotButtonClicked(button);
}
-void AddEditLink::show( const QString& address, const QString& title, const QString& \
target )
-{
- KDialog::show();
- if ( address.isEmpty() ) {
- ui.txtAddress->insertUrl(0, QString());
- ui.txtAddress->setCurrentIndex(0);
- this->setWindowTitle( i18nc( "verb, to insert a link into the text", "Add \
Link" ) );
- } else {
- ui.txtAddress->setCurrentItem( address, true );
- this->setWindowTitle( i18nc( "verb, to modify an existing link", "Edit Link" \
) );
- }
- if ( !title.isEmpty() ) {
- ui.txtTitle->setText( title );
- }
- if ( !target.isEmpty() ) {
- if ( target == "_self" ) {
- ui.comboTarget->setCurrentIndex( 1 );
- } else if ( target == "_blank" ) {
- ui.comboTarget->setCurrentIndex( 2 );
- }
- }
-}
-
void AddEditLink::slotClearLinkCache()
{
- confGroup->writeEntry( "LinksCache", QStringList() );
- QString current = ui.txtAddress->currentText();
- ui.txtAddress->clear();
- ui.txtAddress->addItem( current );
- ui.txtAddress->setCurrentIndex( 0 );
- ui.txtAddress->completionObject()->clear();
+ d->confGroup->writeEntry( "LinksCache", QStringList() );
+ QString current = d->ui.txtAddress->currentText();
+ d->ui.txtAddress->clear();
+ d->ui.txtAddress->addItem( current );
+ d->ui.txtAddress->setCurrentIndex( 0 );
+ d->ui.txtAddress->completionObject()->clear();
}
#include "composer/dialogs/addeditlink.moc"
--- trunk/KDE/kdepim/blogilo/src/composer/dialogs/addeditlink.h #1191122:1191123
@@ -27,7 +27,12 @@
#include <kdialog.h>
-#include "ui_addeditlinkbase.h"
+struct Link{
+public:
+ QString address;
+ QString title;
+ QString target;
+};
/**
Implements a dialog to get user input for link parameters; address, name and target.
@@ -40,21 +45,22 @@
{
Q_OBJECT
public:
- AddEditLink( QWidget *parent = 0 );
+ explicit AddEditLink( const QString& address = QString(), const QString& title = \
QString(), + const QString& target = QString(), QWidget \
*parent = 0 ); + explicit AddEditLink(QWidget* parent = 0);
~AddEditLink();
- void show( const QString& address = QString(), const QString& title = QString(),
- const QString& target = QString() );
-Q_SIGNALS:
- void addLink( const QString& address, const QString& target, const QString& \
title ); + Link &result() const;
private Q_SLOTS:
virtual void slotButtonClicked(int button);
void slotClearLinkCache();
private:
- KConfigGroup *confGroup;
- Ui::AddEditLinkBase ui;
+ void initUi();
+
+ class Private;
+ Private * const d;
};
#endif
--- trunk/KDE/kdepim/blogilo/src/composer/texteditor/texteditor.cpp #1191122:1191123
@@ -37,6 +37,14 @@
#include <klocalizedstring.h>
#include <KColorDialog>
#include <composer/dialogs/addimagedialog.h>
+#include <composer/dialogs/addeditlink.h>
+#include <QContextMenuEvent>
+#include <QTimer>
+#include <qwebframe.h>
+#include <qbuffer.h>
+#include <QFile>
+#include <QDir>
+#include <math.h>
#define ATTACHMENT_IMAGE "image"
#define FORWARD_ACTION(action1, action2) \
@@ -75,9 +83,9 @@
//----------------------------------------------------------------------
WebView::WebView ( QWidget *parent )
- : QWebView ( parent ) {
+ : KWebView ( parent ) {
settings() -> setFontSize ( QWebSettings::DefaultFontSize, 14 );
-
+ page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
setAcceptDrops ( true );
}
@@ -778,10 +786,53 @@
execCommand("foreColor", color.name());
}
+
+// shamelessly copied from Qt Demo Browser
+static QUrl guessUrlFromString(const QString &string)
+{
+ QString urlStr = string.trimmed();
+ QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*"));
+
+ // Check if it looks like a qualified URL. Try parsing it and see.
+ bool hasSchema = test.exactMatch(urlStr);
+ if (hasSchema) {
+ QUrl url(urlStr, QUrl::TolerantMode);
+ if (url.isValid())
+ return url;
+ }
+
+ // Might be a file.
+ if (QFile::exists(urlStr))
+ return QUrl::fromLocalFile(urlStr);
+
+ // Might be a shorturl - try to detect the schema.
+ if (!hasSchema) {
+ int dotIndex = urlStr.indexOf(QLatin1Char('.'));
+ if (dotIndex != -1) {
+ QString prefix = urlStr.left(dotIndex).toLower();
+ QString schema = (prefix == QLatin1String("ftp")) ? prefix : \
QLatin1String("http"); + QUrl url(schema + QLatin1String("://") + urlStr, \
QUrl::TolerantMode); + if (url.isValid())
+ return url;
+ }
+ }
+
+ // Fall back to QUrl's own tolerant parser.
+ return QUrl(string, QUrl::TolerantMode);
+}
+
void TextEditor::slotAddEditLink()
{
-///TODO
+ QPointer<AddEditLink> addLinkDlg = new AddEditLink(this);
+ if( addLinkDlg->exec() ){
+ Link lnk = addLinkDlg->result();
+ QUrl url = guessUrlFromString(lnk.address);
+ if(url.isValid()){
+ execCommand("createLink", url.toString());
+ //TODO use other parameters
}
+ }
+}
void TextEditor::slotRemoveLink()
{
--- trunk/KDE/kdepim/blogilo/src/composer/texteditor/texteditor.h #1191122:1191123
@@ -32,7 +32,7 @@
#include <QTextEdit>
#include <QLineEdit>
-#include <QtWebKit>
+#include <KWebView>
#include <QUndoCommand>
class QWebView;
@@ -65,7 +65,7 @@
//----------------------------------------------------------------------
-class WebView : public QWebView {
+class WebView : public KWebView {
Q_OBJECT
public:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic