KDE/kdebase/workspace/plasma/containments/panel
Sebastian Sauer
mail at dipe.org
Thu Jan 31 22:23:01 CET 2008
SVN commit 769216 by sebsauer:
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
M +79 -5 panel.cpp
M +13 -0 panel.h
--- trunk/KDE/kdebase/workspace/plasma/containments/panel/panel.cpp #769215:769216
@@ -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,10 +39,13 @@
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),
- m_drawBottom(true)
+ m_drawBottom(true),
+ m_size(48)
{
m_background = new Plasma::Svg("widgets/panel-background", this);
setZValue(150);
@@ -45,9 +54,28 @@
Panel::~Panel()
{
+ delete m_dialog;
delete m_background;
}
+void Panel::init()
+{
+ KConfigGroup cg = config();
+ m_size = cg.readEntry("size", m_size);
+
+ 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 << "!!!!!!!!!!!!!!!!!";
@@ -79,8 +107,7 @@
if (loc == BottomEdge || loc == TopEdge) {
setFormFactor(Plasma::Horizontal);
- //FIXME: don't hardcode 48px
- height = 48;
+ height = m_size;
//FIXME: don't hardcode full width
width = r.width();
@@ -108,8 +135,7 @@
} else if (loc == LeftEdge || loc == RightEdge) {
setFormFactor(Plasma::Vertical);
- //FIXME: don't hardcode 48px
- width = 48;
+ width = m_size;
//FIXME: don't hardcode full height
height = r.height();
@@ -334,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"
--- trunk/KDE/kdebase/workspace/plasma/containments/panel/panel.h #769215:769216
@@ -21,6 +21,10 @@
#include <plasma/containment.h>
+class KDialog;
+class QComboBox;
+class QAction;
+
namespace Plasma
{
class Svg;
@@ -32,6 +36,8 @@
public:
Panel(QObject *parent, const QVariantList &args);
~Panel();
+ void init();
+ QList<QAction*> contextActions();
void constraintsUpdated(Plasma::Constraints constraints);
Qt::Orientations expandingDirections() const;
@@ -40,13 +46,20 @@
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;
bool m_drawBottom : 1;
+ int m_size;
};
More information about the Panel-devel
mailing list