[kde-doc-english] playground/devtools/kte_acomment

Jonathan Schmidt-Dominé devel at the-user.org
Sun Jan 17 02:52:49 CET 2010


SVN commit 1075931 by schmidt-domine:

GUI: Now users can create their own styles without editing rc-files manually.
TODO: Integrate the truncate-option into the in interface (checkbox)
TODO: Add tooltips


 M  +1 -0      CMakeLists.txt  
 M  +112 -8    acommentplugin.cpp  
 M  +1 -0      acommentui.rc  
 M  +18 -8     acommentview.h  
 M  +1 -1      artisticcomment.h  
 A             styledialog.ui  


--- trunk/playground/devtools/kte_acomment/CMakeLists.txt #1075930:1075931
@@ -7,6 +7,7 @@
 
 set(acomment_SRCS artisticcomment.cpp)
 set(ktexteditor_acomment_SRCS acommentplugin.cpp)
+kde4_add_ui_files(ktexteditor_acomment_SRCS styledialog.ui)
 
 add_library(acomment STATIC ${acomment_SRCS})
 kde4_add_plugin(ktexteditor_acomment ${ktexteditor_acomment_SRCS})
--- trunk/playground/devtools/kte_acomment/acommentplugin.cpp #1075930:1075931
@@ -88,7 +88,6 @@
 {
     m_styles.clear();
     QStringList groups = m_config->groupList();
-#define E(str) sub.readEntry(str)
 #define ED(str, def) sub.readEntry(str, def)
     foreach(QString str, groups)
     {
@@ -97,13 +96,12 @@
                                         ED("lineBegin", ""), ED("lineEnd", ""),
                                         ED("textBegin", ""), ED("textEnd", ""),
                                         ED("lfill", " ")[0], ED("rfill", " ")[0],
-                                        ED("minfill", (size_t)0), ED("realWidth", (size_t)60), ED("truncate", true), toTypeEnum(E("type")));
-        kDebug() << str << m_styles[str].begin << m_styles[str].realWidth << m_styles[str].lfill;
+                                        ED("minfill", (size_t)0), ED("realWidth", (size_t)60), ED("truncate", true), toTypeEnum(ED("type", "Left")));
+//         kDebug() << str << m_styles[str].begin << m_styles[str].realWidth << m_styles[str].lfill;
     }
 //     m_styles["Nice C++ License"] = ArtisticComment("/***********************************************************", " ***********************************************************/", " ** ", "", "", " ", ' ', '*', 1, 60, false, ArtisticComment::Left);
 //     m_styles["Doxygen/Javadoc"] = ArtisticComment("/**", " */", " * ", "", "", "", '\0', '\0', 0, 60, true, ArtisticComment::LeftNoFill);
 #undef ED
-#undef E
 }
 
 ACommentPlugin *ACommentPlugin::instance = 0;
@@ -152,19 +150,36 @@
         : QObject(view)
         , KXMLGUIClient(view)
         , m_view(view)
+        , m_dialog(new KDialog(view))
 {
     setComponentData(ACommentPluginFactory::componentData());
 
     KActionMenu *action = new KActionMenu(i18n("Insert \"Artistic Comment\""), this);
-    KMenu *menu = action->menu();
+    m_menu = action->menu();
     QStringList groups = ACommentPlugin::instance->m_styles.keys();
     foreach(QString entry, groups)
-        menu->addAction(entry);
+        m_menu->addAction(entry);
     actionCollection()->addAction("tools_acomment", action);
-    //action->setShortcut(Qt::CTRL + Qt::Key_XYZ);
-    connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(insertAComment(QAction*)));
+    
+    connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(insertAComment(QAction*)));
+    
+    KAction *action2 = new KAction(i18n("Configure \"Artistic Comment\"-styles"), this);
+    actionCollection()->addAction("tools_acomment_config", action2);
+    
+    connect(action2, SIGNAL(triggered()), m_dialog, SLOT(open()));
 
     setXMLFile("acommentui.rc");
+    
+    m_ui.setupUi(m_dialog->mainWidget());
+    m_dialog->setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
+    m_ui.name->addItems(ACommentPlugin::instance->m_styles.keys());
+    m_ui.name->setEditText("");
+    static_cast<KLineEdit*>(m_ui.name->lineEdit())->setClickMessage(i18n("Name of my fantastic style"));
+    
+    connect(m_ui.name, SIGNAL(currentIndexChanged(QString)), this, SLOT(loadStyle(QString)));
+    connect(m_ui.type, SIGNAL(activated(int)), this, SLOT(disableOptions(int)));
+    connect(m_dialog, SIGNAL(applyClicked()), this, SLOT(changeEntry()));
+    connect(m_dialog, SIGNAL(accepted()), this, SLOT(changeEntry()));
 }
 
 ACommentView::~ACommentView()
@@ -173,7 +188,96 @@
 
 void ACommentView::insertAComment(QAction *action)
 {
+    /// @TODO Insert a shortcut here?
     m_view->document()->replaceText(m_view->selectionRange(), ACommentPlugin::instance->m_styles[action->iconText()].apply(m_view->selectionText()));
 }
 
+void ACommentView::loadStyle(QString style)
+{
+    ArtisticComment& ac(ACommentPlugin::instance->m_styles[style]);
+    m_ui.begin->setText(ac.begin);
+    m_ui.end->setText(ac.end);
+    m_ui.lineBegin->setText(ac.lineBegin);
+    m_ui.lineEnd->setText(ac.lineEnd);
+    m_ui.textBegin->setText(ac.textBegin);
+    m_ui.textEnd->setText(ac.textEnd);
+    m_ui.lfill->setText(ac.lfill);
+    m_ui.rfill->setText(ac.rfill);
+    m_ui.minfill->setValue(ac.minfill);
+    m_ui.realWidth->setValue(ac.realWidth);
+    if(m_ui.type->currentIndex() != (int)ac.type)
+    {
+        m_ui.type->setCurrentIndex((int)ac.type);
+        disableOptions((int)ac.type);
+    }
+}
+
+void ACommentView::disableOptions(int type)
+{
+    switch(type)
+    {
+        case ArtisticComment::Left:
+            m_ui.textBegin->setEnabled(false);
+            m_ui.lfill->setEnabled(false);
+            m_ui.textEnd->setEnabled(true);
+            m_ui.rfill->setEnabled(true);
+            m_ui.minfill->setEnabled(true);
+            break;
+        case ArtisticComment::Center:
+            m_ui.textBegin->setEnabled(true);
+            m_ui.lfill->setEnabled(true);
+            m_ui.textEnd->setEnabled(true);
+            m_ui.rfill->setEnabled(true);
+            m_ui.minfill->setEnabled(true);
+            break;
+        case ArtisticComment::Right:
+            m_ui.textBegin->setEnabled(true);
+            m_ui.lfill->setEnabled(true);
+            m_ui.textEnd->setEnabled(false);
+            m_ui.rfill->setEnabled(false);
+            m_ui.minfill->setEnabled(true);
+            break;
+        case ArtisticComment::LeftNoFill:
+            m_ui.textBegin->setEnabled(false);
+            m_ui.lfill->setEnabled(false);
+            m_ui.textEnd->setEnabled(false);
+            m_ui.rfill->setEnabled(false);
+            m_ui.minfill->setEnabled(false);
+            break;
+    }
+}
+
+void ACommentView::changeEntry()
+{
+    QString style = m_ui.name->currentText();
+    if(!m_ui.name->contains(style))
+    {
+        m_ui.name->addItem(style);
+        m_menu->addAction(style);
+    }
+    ArtisticComment& ac(ACommentPlugin::instance->m_styles[style]);
+    ac.begin = m_ui.begin->text();
+    ac.end = m_ui.end->text();
+    ac.textBegin = m_ui.textBegin->text();
+    ac.textEnd = m_ui.textEnd->text();
+    ac.lineBegin = m_ui.lineBegin->text();
+    ac.lineEnd = m_ui.lineEnd->text();
+    {
+        QString tmp = m_ui.lfill->text();
+        if(tmp.size() != 0)
+            ac.lfill = tmp[0];
+        else
+            ac.lfill = ' ';
+        tmp = m_ui.rfill->text();
+        if(tmp.size() != 0)
+            ac.rfill = tmp[0];
+        else
+            ac.rfill = ' ';
+    }
+    ac.truncate = true;
+    ac.type = (ArtisticComment::type_t)m_ui.type->currentIndex();
+    ac.minfill = m_ui.minfill->value();
+    ac.realWidth = m_ui.realWidth->value();
+}
+
 #include "acommentview.moc"
--- trunk/playground/devtools/kte_acomment/acommentui.rc #1075930:1075931
@@ -4,6 +4,7 @@
  <Menu name="tools"><Text>&amp;Tools</Text>
     <separator group="tools_operations" />
     <Action name="tools_acomment" group="tools_operations"/>
+    <Action name="tools_acomment_config" group="tools_operations"/>
  </Menu>
 </MenuBar>
 </kpartplugin>
--- trunk/playground/devtools/kte_acomment/acommentview.h #1075930:1075931
@@ -21,17 +21,27 @@
 #include <KXMLGUIClient>
 
 class QAction;
+class KMenu;
+class KDialog;
 
+#include "ui_styledialog.h"
+
 class ACommentView : public QObject, public KXMLGUIClient
 {
-	Q_OBJECT
-	public:
-		explicit ACommentView(KTextEditor::View *view = 0);
-		~ACommentView();
-	private slots:
-		void insertAComment(QAction *action);
-	private:
-		KTextEditor::View *m_view;
+    Q_OBJECT
+public:
+    explicit ACommentView(KTextEditor::View *view = 0);
+    ~ACommentView();
+private slots:
+    void insertAComment(QAction *action);
+    void disableOptions(int type);
+    void loadStyle(QString name);
+    void changeEntry();
+private:
+    KTextEditor::View *m_view;
+    KMenu *m_menu;
+    KDialog *m_dialog;
+    Ui::StyleDialog m_ui;
 };
 
 #endif
--- trunk/playground/devtools/kte_acomment/artisticcomment.h #1075930:1075931
@@ -28,7 +28,7 @@
     size_t minfill;
     size_t realWidth;
     bool truncate;
-    enum type_t { LeftNoFill, Left, Center, Right } type;
+    enum type_t { Left, Center, Right, LeftNoFill } type;
     ArtisticComment() {}
     ArtisticComment(QString begin, QString end,
                     QString lineBegin, QString lineEnd,



More information about the kde-doc-english mailing list