branches/KDE/4.0/kdebase/workspace/plasma/containments/panel

Riccardo Iaconelli riccardo at kde.org
Sat Feb 16 18:16:19 CET 2008


SVN commit 775785 by ruphy:

Added option to be able to change the size (aka height) of the panel.

* we provide the same 4 different sizes like at KDE3; Tiny (22px), Small (32px), Normal (48px, still default) and Large (64px)
* to call the "Configure Panel" dialog is a bit. Don't right-click on the panel itself since then the "Task manager Settings" are displayed, but click at e.g. the most top ~2pixel of the panel.
* this is work on progress and just an initial start to have that imho at least for small/wide-screen rather important option back.

CC_MAIL: panel-devel at kde.org


Conflicts:

	workspace/plasma/containments/panel/panel.cpp
	workspace/plasma/containments/panel/panel.h


 M  +67 -0     panel.cpp  
 M  +11 -0     panel.h  


--- branches/KDE/4.0/kdebase/workspace/plasma/containments/panel/panel.cpp #775784:775785
@@ -21,8 +21,14 @@
 #include <QApplication>
 #include <QPainter>
 #include <QDesktopWidget>
+#include <QGridLayout>
+#include <QLabel>
+#include <QComboBox>
+#include <QAction>
 
 #include <KDebug>
+#include <KIcon>
+#include <KDialog>
 
 #include <plasma/corona.h>
 #include <plasma/layouts/layout.h>
@@ -33,6 +39,8 @@
 Panel::Panel(QObject *parent, const QVariantList &args)
     : Containment(parent, args),
       m_cachedBackground(0),
+      m_dialog(0),
+      m_configureAction(0),
       m_drawTop(true),
       m_drawLeft(true),
       m_drawRight(true),
@@ -46,6 +54,7 @@
 
 Panel::~Panel()
 {
+    delete m_dialog;
     delete m_background;
 }
 
@@ -57,6 +66,16 @@
     Containment::init();
 }
 
+QList<QAction*> Panel::contextActions()
+{
+    if (! m_configureAction) {
+        m_configureAction = new QAction(i18n("Configure Panel..."), this);
+        m_configureAction->setIcon(KIcon("configure"));
+        connect(m_configureAction, SIGNAL(triggered()), this, SLOT(configure()));
+    }
+    return QList<QAction*>() << m_configureAction;
+}
+
 void Panel::constraintsUpdated(Plasma::Constraints constraints)
 {
     //kDebug() << "constraints updated with" << constraints << "!!!!!!!!!!!!!!!!!";
@@ -341,6 +360,54 @@
     painter->drawPixmap(contentsRect, *m_cachedBackground, contentsRect);
 }
 
+void Panel::configure()
+{
+    if (! m_dialog) {
+        m_dialog = new KDialog();
+        m_dialog->setCaption( i18nc("@title:window","Configure Panel") );
+        m_dialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
+        connect(m_dialog, SIGNAL(applyClicked()), this, SLOT(applyConfig()));
+        connect(m_dialog, SIGNAL(okClicked()), this, SLOT(applyConfig()));
+
+        QWidget *p = m_dialog->mainWidget();
+        QGridLayout *l = new QGridLayout(p);
+        p->setLayout(l);
+
+        QLabel *sizeLabel = new QLabel(i18n("Size:"), p);
+        l->addWidget(sizeLabel, 0, 0);
+        m_sizeCombo = new QComboBox(p);
+        sizeLabel->setBuddy(m_sizeCombo);
+        l->addWidget(m_sizeCombo, 0, 1);
+        m_sizeCombo->addItem(i18n("Tiny"), QVariant(24));
+        m_sizeCombo->addItem(i18n("Small"), QVariant(32));
+        m_sizeCombo->addItem(i18n("Normal"), QVariant(48));
+        m_sizeCombo->addItem(i18n("Large"), QVariant(64));
+        l->setColumnStretch(1,1);
+
+        bool found = false;
+        for (int i = 0; i < m_sizeCombo->count(); ++i) {
+            if (m_sizeCombo->itemData(i).toInt() == m_size) {
+                m_sizeCombo->setCurrentIndex(i);
+                found = true;
+                break;
+            }
+        }
+        if (! found) {
+            m_sizeCombo->setCurrentIndex(m_sizeCombo->count() - 1);
+        }
+    }
+    m_dialog->show();
+}
+
+void Panel::applyConfig()
+{
+    KConfigGroup cg = config();
+    m_size = m_sizeCombo->itemData(m_sizeCombo->currentIndex()).toInt();
+    cg.writeEntry("size", m_size);
+
+    updateConstraints();
+}
+
 K_EXPORT_PLASMA_APPLET(panel, Panel)
 
 #include "panel.moc"
--- branches/KDE/4.0/kdebase/workspace/plasma/containments/panel/panel.h #775784:775785
@@ -21,6 +21,10 @@
 
 #include <plasma/containment.h>
 
+class KDialog;
+class QComboBox;
+class QAction;
+
 namespace Plasma
 {
     class Svg;
@@ -33,6 +37,7 @@
     Panel(QObject *parent, const QVariantList &args);
     ~Panel();
     void init();
+    QList<QAction*> contextActions();
 
     void constraintsUpdated(Plasma::Constraints constraints);
     Qt::Orientations expandingDirections() const;
@@ -41,9 +46,15 @@
                         const QStyleOptionGraphicsItem *option,
                         const QRect &contentsRect);
     void paintBackground(QPainter *painter, const QRect &contentsRect);
+private slots:
+    void configure();
+    void applyConfig();
 private:
     Plasma::Svg *m_background;
     QPixmap* m_cachedBackground;
+    KDialog* m_dialog;
+    QComboBox* m_sizeCombo;
+    QAction* m_configureAction;
     bool m_drawTop : 1;
     bool m_drawLeft : 1;
     bool m_drawRight : 1;


More information about the Panel-devel mailing list