From kwrite-devel Sat Jan 10 11:02:04 2009 From: =?utf-8?q?J=C3=A9r=C3=B4me_Lodewyck?= Date: Sat, 10 Jan 2009 11:02:04 +0000 To: kwrite-devel Subject: RGB color code plugin Message-Id: <200901101202.04637.lodewyck () free ! fr> X-MARC-Message: https://marc.info/?l=kwrite-devel&m=123158946607264 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_sAIaJHDFkNw6JJU" --Boundary-00=_sAIaJHDFkNw6JJU Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I have written a small KTextEditor plugin that opens a color selection dia= log=20 and inserts the corresponding rgb color in HTML form (see attachment). If i= t=20 is OK, I would like to commit it somewhere. Is there a place for such a=20 plugin ? J=C3=A9r=C3=B4me --Boundary-00=_sAIaJHDFkNw6JJU Content-Type: text/x-diff; charset="utf-8"; name="rgbcolor.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rgbcolor.diff" Index: ktexteditor_rgbcolorui.rc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- ktexteditor_rgbcolorui.rc (r=C3=A9vision 0) +++ ktexteditor_rgbcolorui.rc (r=C3=A9vision 0) @@ -0,0 +1,9 @@ + + + + &Tools + + + + + Index: ktexteditor_rgbcolor.desktop =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- ktexteditor_rgbcolor.desktop (r=C3=A9vision 0) +++ ktexteditor_rgbcolor.desktop (r=C3=A9vision 0) @@ -0,0 +1,20 @@ +[Desktop Entry] +X-KDE-Library=3Dktexteditor_rgbcolor +X-KDE-PluginInfo-Author=3D +X-KDE-PluginInfo-Email=3D +X-KDE-PluginInfo-Name=3Dktexteditorrgbcolor +X-KDE-PluginInfo-Version=3D0.1 +X-KDE-PluginInfo-Website=3Dhttp://kate.kde.org +X-KDE-PluginInfo-Category=3DEditor +X-KDE-PluginInfo-Depends=3D +X-KDE-PluginInfo-License=3DGPL +X-KDE-PluginInfo-EnabledByDefault=3Dtrue +X-KDE-ParentApp=3Dkate +X-KDE-Version=3D4.0 +X-KDE-ServiceTypes=3DKTextEditor/Plugin +Type=3DService +Icon=3Dfill-color +Name=3DInsert RGB color code +Name[fr]=3DIns=C3=A9rer un code couleur RGB +Comment=3DInsert the selected RGB color code in HTML format +Comment[fr]=3DIns=C3=A9rer le code couleur RGB s=C3=A9lectionn=C3=A9 au fo= rmat HTML Index: rgbcolorplugin.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- rgbcolorplugin.cpp (r=C3=A9vision 0) +++ rgbcolorplugin.cpp (r=C3=A9vision 0) @@ -0,0 +1,115 @@ +/* This file is part of the KDE libraries + Copyright (C) 2008 J=C3=A9r=C3=B4me Lodewyck + Copyright (C) 2002 Anders Lund + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "rgbcolorplugin.h" +#include "rgbcolorplugin.moc" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +K_PLUGIN_FACTORY(RgbColorPluginFactory, registerPlugin();) +K_EXPORT_PLUGIN(RgbColorPluginFactory(KAboutData( "ktexteditor_rgbcolor", = "ktexteditor_plugins", ki18n("RGB Color"), "0.1", ki18n("Insert RGB color c= ode"), KAboutData::License_LGPL_V2 ))) + +//BEGIN RgbColorPlugin +RgbColorPlugin::RgbColorPlugin(QObject* parent, const QVariantList&) + : KTextEditor::Plugin(parent) +{ +} + +RgbColorPlugin::~RgbColorPlugin() +{ +} + +void RgbColorPlugin::addView(KTextEditor::View *view) +{ + RgbColorPluginView *nview =3D new RgbColorPluginView(view, "RGB Color Plu= gin"); + m_views.append(nview); +} + +void RgbColorPlugin::removeView(KTextEditor::View *view) +{ + int z =3D 0; + // Loop written for the unlikely case of a view being added more than once + while (z < m_views.count()) + { + RgbColorPluginView *nview =3D m_views.at(z); + if (nview->parentClient() =3D=3D view) + { + m_views.removeAll(nview); + delete nview; + } + else + ++z; + } +} +//END RgbColorPlugin + +//BEGIN RgbColorPluginView +RgbColorPluginView::RgbColorPluginView(KTextEditor::View *view, const char= *name) + : QObject(view) + , KXMLGUIClient(view) +{ + setObjectName(name); + + setComponentData(RgbColorPluginFactory::componentData()); + + KAction *action =3D new KAction(KIcon("fill-color"), i18n("Insert RGB col= or code..."), this); + actionCollection()->addAction("tools_insert_rgbcolor", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(slotInsertColor())); + + setXMLFile("ktexteditor_rgbcolorui.rc"); +} + +void RgbColorPluginView::slotInsertColor() +{ + QColor color; + + if (KColorDialog::getColor(color, (QWidget*)parent()) =3D=3D QDialog::Acc= epted) + insertColor(color); +} + +void RgbColorPluginView::insertColor(QColor& color) +{ + int r, g, b; + color.getRgb(&r, &g, &b); + QString colorCode; + colorCode.sprintf("#%02X%02X%02X", r, g, b); + + KTextEditor::View* v =3D (KTextEditor::View*)parent(); + if (v->selection()) + v->document()->replaceText(v->selectionRange(), colorCode); + else + v->document()->insertText(v->cursorPosition(), colorCode); +} + +//END RgbColorPluginView + Index: CMakeLists.txt =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- CMakeLists.txt (r=C3=A9vision 0) +++ CMakeLists.txt (r=C3=A9vision 0) @@ -0,0 +1,14 @@ +########### next target ############### + +set(ktexteditor_rgbcolor_PART_SRCS rgbcolorplugin.cpp ) + +kde4_add_plugin(ktexteditor_rgbcolor ${ktexteditor_rgbcolor_PART_SRCS}) + +target_link_libraries(ktexteditor_rgbcolor ${KDE4_KIO_LIBS} ktexteditor kd= eui kfile) + +install(TARGETS ktexteditor_rgbcolor DESTINATION ${PLUGIN_INSTALL_DIR} ) + +########### install files ############### + +install( FILES ktexteditor_rgbcolor.desktop DESTINATION ${SERVICES_INSTA= LL_DIR} ) +install( FILES ktexteditor_rgbcolorui.rc DESTINATION ${DATA_INSTALL_DIR}= /ktexteditor_rgbcolor ) Index: rgbcolorplugin.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- rgbcolorplugin.h (r=C3=A9vision 0) +++ rgbcolorplugin.h (r=C3=A9vision 0) @@ -0,0 +1,57 @@ +/* This file is part of the KDE libraries + Copyright (C) 2008 J=C3=A9r=C3=B4me Lodewyck + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _RGBCOLOR_PLUGIN_H_ +#define _RGBCOLOR_PLUGIN_H_ + +#include +#include + +#include +#include + +class RgbColorPlugin : public KTextEditor::Plugin +{ + Q_OBJECT + + public: + explicit RgbColorPlugin(QObject *parent =3D 0, + const QVariantList &args =3D QVariantList()); + virtual ~RgbColorPlugin(); + + void addView(KTextEditor::View *view); + void removeView(KTextEditor::View *view); + + private: + QList m_views; +}; + +class RgbColorPluginView : public QObject, public KXMLGUIClient +{ + Q_OBJECT + public: + explicit RgbColorPluginView(KTextEditor::View *view, const char *name = =3D 0); + ~RgbColorPluginView() {} + public Q_SLOTS: + // display a color dialog, and insert the chosen color + void slotInsertColor(); + private: + void insertColor(QColor& color); +}; + +#endif // _RGBCOLOR_PLUGIN_H_ --Boundary-00=_sAIaJHDFkNw6JJU Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ KWrite-Devel mailing list KWrite-Devel@kde.org https://mail.kde.org/mailman/listinfo/kwrite-devel --Boundary-00=_sAIaJHDFkNw6JJU--