[SCM] Kaboom - Debian KDE 3->4 migration tool branch, master, updated. a2434946a7bbd875b22f6930d60970158091ae6a

George Kiagiadakis gkiagia-guest at alioth.debian.org
Sun Feb 22 00:16:48 UTC 2009


The following commit has been merged in the master branch:
commit a2434946a7bbd875b22f6930d60970158091ae6a
Author: George Kiagiadakis <gkiagia at users.sourceforge.net>
Date:   Sun Feb 22 02:01:24 2009 +0200

    Initial commit of RichRadioButton.
    This is a replacement for QRadioButton that supports rich text and word wrap.
    I hope it is worth it... Comments/suggestions welcome :)

diff --git a/choicepage.cpp b/choicepage.cpp
index 7a8881c..b6c7738 100644
--- a/choicepage.cpp
+++ b/choicepage.cpp
@@ -16,16 +16,17 @@
 */
 #include "choicepage.h"
 #include "diroperations/diroperations.h"
+#include "richradiobutton.h"
 
 class ChoicePagePrivate
 {
   public:
     ChoicePagePrivate() : backup(NULL) {}
     QLabel *text;
-    QRadioButton *clean;
-    QRadioButton *migrate;
-    QRadioButton *move;
-    QRadioButton *merge;
+    RichRadioButton *clean;
+    RichRadioButton *migrate;
+    RichRadioButton *move;
+    RichRadioButton *merge;
     QButtonGroup *buttons;
     QCheckBox *backup;
     bool haskde4dir;
@@ -44,19 +45,19 @@ ChoicePage::ChoicePage(QWidget *parent) : QWizardPage(parent)
   lay->addWidget(d->text);
   if(d->haskdedir)
   {
-    d->migrate = new QRadioButton("Migrate settings from KDE3 to KDE4 (recommended)",this);
+    d->migrate = new RichRadioButton("Migrate settings from KDE3 to KDE4 (recommended)",this);
     d->buttons->addButton(d->migrate,MigrationTool::Migrate);
     lay->addWidget(d->migrate);
     d->migrate->setChecked(true);
   }
   if(d->haskde4dir)
   {
-    d->move = new QRadioButton("Move settings from KDE 4 dir and <b>replace</b> settings from KDE 3");
+    d->move = new RichRadioButton("Move settings from KDE 4 dir and <b>replace</b> settings from KDE 3");
     d->buttons->addButton(d->move,MigrationTool::Move);
     lay->addWidget(d->move);
     if(d->haskdedir)
     {
-      d->merge = new QRadioButton("Merge settings from KDE3 and KDE4 (experimental)");
+      d->merge = new RichRadioButton("Merge settings from KDE3 and KDE4 (experimental)");
       d->buttons->addButton(d->merge,MigrationTool::Merge);
       lay->addWidget(d->merge);
     }
@@ -65,7 +66,7 @@ ChoicePage::ChoicePage(QWidget *parent) : QWizardPage(parent)
       d->move->setChecked(true);
     }
   }
-  d->clean = new QRadioButton("Start with a fresh KDE. This option will <b>remove</b> data and settings such as contacts, local stored mails, accounts in KMail and Kopete, bookmarks and other such data",this);
+  d->clean = new RichRadioButton("Start with a fresh KDE. This option will <b>remove</b> data and settings such as contacts, local stored mails, accounts in KMail and Kopete, bookmarks and other such data",this);
   d->buttons->addButton(d->clean,MigrationTool::Clean);
   lay->addWidget(d->clean);
   if(d->haskdedir) //if no kdedir, nothing to backup.
diff --git a/kaboom.pro b/kaboom.pro
index 5dda1f4..2eea8ad 100644
--- a/kaboom.pro
+++ b/kaboom.pro
@@ -19,6 +19,7 @@ HEADERS += \
       warningpage.h \
       diroperations/diroperations.h \
       diroperations/progresswidget.h \
+      richradiobutton.h
       
       
 SOURCES += \
@@ -30,5 +31,5 @@ SOURCES += \
       warningpage.cpp \
       diroperations/diroperations.cpp \
       diroperations/progresswidget.cpp \
-      
+      richradiobutton.cpp
       
diff --git a/richradiobutton.cpp b/richradiobutton.cpp
new file mode 100644
index 0000000..d90d104
--- /dev/null
+++ b/richradiobutton.cpp
@@ -0,0 +1,146 @@
+/*
+    Copyright (C) 2009  George Kiagiadakis <gkiagia at users.sourceforge.net>
+
+    This library is free software; you can redistribute it and/or modify
+    it under the terms of the GNU Lesser General Public License as published
+    by the Free Software Foundation; either version 2.1 of the License, or
+    (at your option) any later version.
+
+    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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "richradiobutton.h"
+
+#include <QtCore/QEvent>
+#include <QtGui/QRadioButton>
+#include <QtGui/QLabel>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QStyle>
+#include <QtGui/QStylePainter>
+#include <QtGui/QStyleOptionButton>
+
+//#include <QtCore/QDebug>
+
+class EventEater : public QObject
+{
+public:
+    EventEater(QObject *parent) : QObject(parent) {}
+protected:
+    virtual bool eventFilter(QObject *watched, QEvent *event);
+};
+
+bool EventEater::eventFilter(QObject *watched, QEvent *event)
+{
+    switch(event->type()) {
+        case QEvent::KeyPress:
+        case QEvent::KeyRelease:
+        case QEvent::MouseButtonPress:
+        case QEvent::MouseButtonRelease:
+        case QEvent::MouseMove:
+        case QEvent::HoverEnter:
+        case QEvent::HoverLeave:
+        case QEvent::HoverMove:
+            event->ignore();
+            return true;
+        default:
+            return QObject::eventFilter(watched, event);
+    }
+}
+
+
+class PrivateRadioButton : public QRadioButton
+{
+public:
+    PrivateRadioButton(RichRadioButton *parent);
+
+protected:
+    virtual void paintEvent(QPaintEvent *event);
+
+private:
+    RichRadioButton *q;
+};
+
+PrivateRadioButton::PrivateRadioButton(RichRadioButton *parent)
+    : QRadioButton(parent), q(parent)
+{
+    setMouseTracking(false); //disable it, since QRadioButton enables it...
+}
+
+void PrivateRadioButton::paintEvent(QPaintEvent *event)
+{
+    Q_UNUSED(event);
+    QStylePainter p(this);
+    QStyleOptionButton opt;
+    opt.initFrom(q);
+    opt.rect = rect();
+    opt.state |= (q->isChecked()) ? QStyle::State_On : QStyle::State_Off;
+    p.drawControl(QStyle::CE_RadioButton, opt);
+}
+
+
+struct RichRadioButton::Private
+{
+    PrivateRadioButton *m_button;
+    QLabel *m_label;
+
+    void init(RichRadioButton *q);
+};
+
+void RichRadioButton::Private::init(RichRadioButton *q)
+{
+    QHBoxLayout *layout = new QHBoxLayout(q);
+    m_button = new PrivateRadioButton(q);
+    m_button->setFocusPolicy(Qt::NoFocus);
+    m_label = new QLabel(q);
+    m_label->setWordWrap(q);
+
+    layout->addWidget(m_button);
+    layout->addWidget(m_label);
+
+    m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+    //install event filter to reject keyboard & mouse events from child objects
+    EventEater *eventEater = new EventEater(q);
+    m_button->installEventFilter(eventEater);
+    m_label->installEventFilter(eventEater);
+
+    q->setCheckable(true);
+    q->setAutoExclusive(true);
+}
+
+
+RichRadioButton::RichRadioButton(QWidget *parent)
+    : QAbstractButton(parent), d(new Private)
+{
+    d->init(this);
+}
+
+RichRadioButton::RichRadioButton(const QString & text, QWidget *parent)
+    : QAbstractButton(parent), d(new Private)
+{
+    d->init(this);
+    setText(text);
+}
+
+RichRadioButton::~RichRadioButton()
+{
+    delete d;
+}
+
+void RichRadioButton::setText(const QString & text)
+{
+    d->m_label->setText(text);
+    QAbstractButton::setText(text);
+}
+
+void RichRadioButton::paintEvent(QPaintEvent *event)
+{
+    d->m_button->update(); //this is for reacting in hover events.
+    QWidget::paintEvent(event);
+}
diff --git a/diroperations/progresswidget.h b/richradiobutton.h
similarity index 57%
copy from diroperations/progresswidget.h
copy to richradiobutton.h
index 6cd327c..d03841f 100644
--- a/diroperations/progresswidget.h
+++ b/richradiobutton.h
@@ -14,28 +14,29 @@
     You should have received a copy of the GNU Lesser General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-#ifndef PROGRESSWIDGET_H
-#define PROGRESSWIDGET_H
+#ifndef RICHRADIOBUTTON_H
+#define RICHRADIOBUTTON_H
 
-#include "diroperations.h"
-#include <QWidget>
-class QLabel;
-class QProgressBar;
+#include <QtGui/QAbstractButton>
 
-class ProgressWidget : public QWidget, public DirOperations::ProgressDialogInterface
+class RichRadioButton : public QAbstractButton
 {
+    Q_OBJECT
 public:
-    ProgressWidget(QWidget *parent = 0);
+    explicit RichRadioButton(QWidget *parent = 0);
+    explicit RichRadioButton(const QString & text, QWidget *parent = 0);
+    virtual ~RichRadioButton();
 
-    virtual void setLabelText(const QString & text);
-    virtual bool wasCanceled() const;
-    virtual void setMaximum(int max);
-    virtual void setValue(int value);
-    virtual void processEvents();
+    //not virtual, do not call the parent's implementation!
+    void setText(const QString & text);
+
+protected:
+    //reimplemented because it's pure virtual in QAbstractButton
+    virtual void paintEvent(QPaintEvent *event);
 
 private:
-    QLabel *m_label;
-    QProgressBar *m_progressBar;
+    struct Private;
+    Private * const d;
 };
 
 #endif

-- 
Kaboom - Debian KDE 3->4 migration tool



More information about the pkg-kde-commits mailing list