Commit e4dc48b0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Now we use composereditorng

parent 774c9322
......@@ -23,10 +23,7 @@ set(blogilo_SRCS
syncuploader.cpp
composer/htmleditor.cpp
composer/stylegetter.cpp
composer/dialogs/addeditlink.cpp
composer/dialogs/addmediadialog.cpp
composer/dialogs/addeditimage.cpp
composer/texteditor.cpp
composer/blogilocomposerview.cpp
composer/blogilocomposereditor.cpp
......@@ -57,8 +54,6 @@ kde4_add_ui_files(
blogsettingsbase.ui
uploadmediabase.ui
composer/dialogs/addmediadialogbase.ui
composer/dialogs/editimagebase.ui
composer/dialogs/addeditlinkbase.ui
)
kde4_add_kcfg_files( blogilo_SRCS settings.kcfgc)
......@@ -78,4 +73,3 @@ install( TARGETS blogilo ${INSTALL_TARGETS_DEFAULT_ARGS} )
install( PROGRAMS ../blogilo.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
install( FILES blogilo.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
install( FILES blogiloui.rc composer/TextEditorInitialHtml DESTINATION ${DATA_INSTALL_DIR}/blogilo )
<html>
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<script type="text/javascript">
function mouseEventHandler(mEvent)
{
// var node = mEvent.srcElement;
}
function setReadOnly(readOnly)
{
var node = document.getElementById("editableArea");
if (readOnly)
node.setAttribute("contenteditable", "false");
else
node.setAttribute("contenteditable", "true");
}
function getCurrentStyle(node, prop)
{
return document.defaultView.getComputedStyle(node, null).getPropertyValue(prop);
}
function getUserSelection()
{
var userSelection;
if (window.getSelection)
{
userSelection = window.getSelection();
}
else
{
return null;
}
return userSelection;
}
function getAlignment()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "text-align");
}
function getFontFamily()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "font-family");
}
function getFontSize()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "font-size");
}
function getForegroundColor()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "color");
}
function getBackgroundColor()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "background-color");
}
function getTextDirection()
{
var node = getUserSelection().anchorNode.parentNode;
return getCurrentStyle(node, "direction");
}
function replaceHtml(htmlString)
{
var node = document.getElementById("editableArea");
node.innerHTML = htmlString;
// adjustImagesPath();
}
function getHtml()
{
var node = document.getElementById("editableArea");
return node.innerHTML;
}
function replaceImageSrc(src, dest)
{
var html = getHtml();
var res = html.replace(src, dest);
replaceHtml(res);
}
function insertLink(href, target, title)
{
if (window.getSelection)
{
var userSelection = window.getSelection();
var lnk = document.createElement("a");
lnk.href = href;
lnk.target = target;
lnk.title = title;
var range = userSelection.getRangeAt(0);
range.surroundContents(lnk);
} else
alert("Select something");
}
</script>
</head>
<body id="editableArea" contenteditable="true" onMouseDown="javaScript:mouseEventHandler(event);"></body>
</html>
/*
This file is part of Blogilo, A KDE Blogging Client
Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/
*/
#include "addeditimage.h"
#ifdef WIN32
#include <QFileDialog>
#else
#include <KFileDialog>
#endif
#include <kmessagebox.h>
#include <kdebug.h>
#include "bilbomedia.h"
AddEditImage::AddEditImage(QWidget* parent, QMap< QString, QString > mediaToEdit)
: AddMediaDialog(parent), ratio(0), settingNewImageSize(false)
{
editFrame = new QFrame(this);
editFrame->setFrameShape(QFrame::StyledPanel);
editFrame->setFrameShadow(QFrame::Raised);
editImageWidgetUi.setupUi( editFrame );
// editImageWidgetUi.btnKeepRatio->setIcon(KIcon("")); TODO
ui.verticalLayout->addWidget( editFrame );
ui.radiobtnRemoteUrl->setEnabled( true );
if(mediaToEdit.isEmpty()){
setWindowTitle( i18n( "Add Image" ) );
isEditing = false;
} else {
isEditing = true;
setWindowTitle( i18n( "Edit Image" ) );
_selectedMedia = mediaToEdit;
settingNewImageSize = true;
editImageWidgetUi.spinboxWidth->setValue( mediaToEdit["width"].toInt() );
editImageWidgetUi.spinboxHeight->setValue( mediaToEdit["height"].toInt() );
settingNewImageSize = false;
updateRatio();
editImageWidgetUi.txtTitle->setText( mediaToEdit["title"] );
editImageWidgetUi.txtAltText->setText( mediaToEdit["alt"] );
setAlignment(mediaToEdit["align"]);
ui.urlReqLineEdit->setText( mediaToEdit["url"] );
if( !mediaToEdit.value("link").isEmpty() ) {
editImageWidgetUi.txtLink->setText( mediaToEdit["link"] );
} else{
editImageWidgetUi.labelLink->setVisible(false);
editImageWidgetUi.txtLink->setVisible(false);
}
}
connect(editImageWidgetUi.spinboxWidth, SIGNAL(valueChanged(int)),
this, SLOT(slotCheckRatio(int)));
connect(editImageWidgetUi.spinboxHeight, SIGNAL(valueChanged(int)),
this, SLOT(slotCheckRatio(int)) );
// QStringList mimeFilter;
// mimeFilter << "image/gif" << "image/jpeg" << "image/png" ;
// ui.kurlreqMediaUrl->fileDialog()->setMimeFilter( mimeFilter );
}
AddEditImage::~AddEditImage()
{
kDebug();
}
void AddEditImage::slotSelectLocalFile()
{
QString path;
#ifdef WIN32
path = QFileDialog::getOpenFileName( this, i18n("Choose a file"), QString(), i18n("Images (*.png *.gif *.jpg)" ) );//krazy:exclude=qclasses KFileDialog has problem on WIN32 now
#else
path = KFileDialog::getImageOpenUrl( KUrl(), this, i18n("Choose a file") ).path();
#endif
QImage img(path);
if(path.isEmpty() || img.isNull())
return;
ui.urlReqLineEdit->setText(path);
editImageWidgetUi.btnKeepRatio->setChecked(true);
settingNewImageSize = true;
editImageWidgetUi.spinboxWidth->setValue(img.width());
editImageWidgetUi.spinboxHeight->setValue(img.height());
settingNewImageSize = false;
updateRatio();
}
void AddEditImage::slotButtonClicked(int button)
{
kDebug();
_selectedMedia["width"] = QString::number(editImageWidgetUi.spinboxWidth->value());
_selectedMedia["height"] = QString::number(editImageWidgetUi.spinboxHeight->value());
_selectedMedia["title"] = editImageWidgetUi.txtTitle->text();
_selectedMedia["link"] = editImageWidgetUi.txtLink->text();
_selectedMedia["alt"] = editImageWidgetUi.txtAltText->text();
_selectedMedia["align"] = getAlignment();
if(isEditing)
_selectedMedia["url"] = ui.urlReqLineEdit->text();
// kDebug()<<_selectedMedia;
AddMediaDialog::slotButtonClicked(button);
}
QString AddEditImage::getAlignment()
{
switch(editImageWidgetUi.alignment->currentIndex()){
case 1:
return "right";
break;
case 2:
return "left";
break;
case 0:
default:
return QString();
break;
}
}
void AddEditImage::setAlignment(const QString& align)
{
if(align.isEmpty())
editImageWidgetUi.alignment->setCurrentIndex(0);
else if(align == "right")
editImageWidgetUi.alignment->setCurrentIndex(1);
else if(align == "left")
editImageWidgetUi.alignment->setCurrentIndex(2);
}
void AddEditImage::slotCheckRatio(int value)
{
if(settingNewImageSize)
return;
settingNewImageSize = true;
if(editImageWidgetUi.btnKeepRatio->isChecked() && ratio > 0) {
if(sender() == editImageWidgetUi.spinboxHeight){
editImageWidgetUi.spinboxWidth->setValue(value*ratio);
} else if(sender() == editImageWidgetUi.spinboxWidth){
editImageWidgetUi.spinboxHeight->setValue(value/ratio);
}
}
settingNewImageSize = false;
}
void AddEditImage::updateRatio()
{
if( editImageWidgetUi.spinboxWidth->value() > 0 &&
editImageWidgetUi.spinboxHeight->value() > 0 )
ratio = (double) editImageWidgetUi.spinboxWidth->value()
/
(double) editImageWidgetUi.spinboxHeight->value();
}
#include "composer/dialogs/addeditimage.moc"
/*
This file is part of Blogilo, A KDE Blogging Client
Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/
*/
#ifndef ADDIMAGEDIALOG_H
#define ADDIMAGEDIALOG_H
#include "addmediadialog.h"
#include "ui_editimagebase.h"
class QFrame;
class BilboMedia;
/**
@author
*/
class AddEditImage : public AddMediaDialog
{
Q_OBJECT
public:
AddEditImage(QWidget* parent, QMap<QString, QString> mediaToEdit = (QMap<QString, QString>()));
~AddEditImage();
protected:
// virtual void addOtherMediaAttributes();
virtual void slotButtonClicked(int button);
protected slots:
virtual void slotSelectLocalFile();
void slotCheckRatio(int value);
private:
void updateRatio();
QString getAlignment();
void setAlignment(const QString& align);
QFrame *editFrame;
Ui::EditImageBase editImageWidgetUi;
bool isEditing;
double ratio;
bool settingNewImageSize;
};
#endif
/*
This file is part of Blogilo, A KDE Blogging Client
Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/
*/
#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 ), d(new Private)
{
initUi();
d->ui.txtAddress->insertUrl(0, QString());
d->ui.txtAddress->setCurrentIndex(0);
this->setWindowTitle( i18nc( "verb, to insert a link into the text", "Add Link" ) );
}
AddEditLink::AddEditLink(const QString& address, const QString& title, const QString& target,
QWidget* parent): KDialog(parent), d(new Private)
{
initUi();
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 );
}
}
}
AddEditLink::~AddEditLink()
{
d->confGroup->writeEntry( "Size", size() );
d->confGroup->sync();
delete d->confGroup;
delete d;
}
void AddEditLink::initUi()
{
QWidget *dialog = new QWidget( this );
d->ui.setupUi( dialog );
d->ui.btnClear->setIcon(KIcon("edit-clear"));
this->setMainWidget( dialog );
this->resize( dialog->width(), dialog->height() );
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);
d->ui.txtAddress->setCompletionMode(KGlobalSettings::CompletionPopupAuto);
d->ui.txtAddress->setFocus();
resize( d->confGroup->readEntry("Size", this->size()) );
connect(d->ui.btnClear, SIGNAL(clicked(bool)), SLOT(slotClearLinkCache()) );
}
Link& AddEditLink::result() const
{
return d->result;
}
void AddEditLink::slotButtonClicked( int button )
{
if(button == KDialog::Ok) {
QString link = d->ui.txtAddress->currentText();
if ( link.isEmpty() )
return;
QString linkTarget;
if ( d->ui.comboTarget->currentIndex() == 1 ) {
linkTarget = "_self";
} else if ( d->ui.comboTarget->currentIndex() == 2 ) {
linkTarget = "_blank";
}
const QString target = linkTarget;
if( Settings::urlCachingEnabled() ) {
QStringList linksList = d->confGroup->readEntry("LinksCache", QStringList());
linksList.append(link);
d->confGroup->writeEntry("LinksCache", linksList );
d->confGroup->sync();
}
d->result.address = link;
d->result.target = target;
d->result.title = d->ui.txtTitle->text();
accept();
} else
KDialog::slotButtonClicked(button);
}
void AddEditLink::slotClearLinkCache()
{
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"
/*
This file is part of Blogilo, A KDE Blogging Client
Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/
*/
#ifndef ADDEDITLINK_H
#define ADDEDITLINK_H
#include <kdialog.h>
struct Link{
public:
QString address;
QString title;
QString target;
};
/**
Implements a dialog to get user input for link parameters; address, name and target.
@author Mehrdad Momeny <mehrdad.momeny@gmail.com>
@author Golnaz Nilieh <g382nilieh@gmail.com>
*/
class AddEditLink: public KDialog
{
Q_OBJECT
public:
explicit AddEditLink( const QString& address = QString(), const QString& title = QString(),
const QString& target = QString(), QWidget *parent = 0 );
explicit AddEditLink(QWidget* parent = 0);
~AddEditLink();
Link &result() const;
private Q_SLOTS:
virtual void slotButtonClicked(int button);
void slotClearLinkCache();
private:
void initUi();
class Private;
Private * const d;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddEditLinkBase</class>
<widget class="QWidget" name="AddEditLinkBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>114</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">