[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdeui
From: Urs Wolfer <uwolfer () kde ! org>
Date: 2008-03-21 20:18:01
Message-ID: 1206130681.014786.15670.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 788541 by uwolfer:
Ability to change the title of the KMenu in KSystemTrayIcon. (required in Akonadi)
Clean up the code of KMenu::addTitle (looks now with Plastique like in KDE 3, and way \
nicer in Oxygen style than before). Reviewed by Toma.
M +17 -6 util/ksystemtrayicon.cpp
M +21 -2 util/ksystemtrayicon.h
M +14 -29 widgets/kmenu.cpp
--- trunk/KDE/kdelibs/kdeui/util/ksystemtrayicon.cpp #788540:788541
@@ -29,19 +29,17 @@
#include "kactioncollection.h"
#include "kstandardaction.h"
-#include <config.h>
-
#ifdef Q_WS_X11
#include <kwindowsystem.h>
#include <QX11Info>
#endif
-#include <kconfig.h>
#include <kiconloader.h>
#include <kapplication.h>
+#include <kconfiggroup.h>
#include <QMouseEvent>
-#include <kconfiggroup.h>
+#include <QToolButton>
class KSystemTrayIconPrivate
{
@@ -64,6 +62,7 @@
KActionCollection* actionCollection;
KMenu* menu;
QWidget* window;
+ QAction* titleAction;
bool onAllDesktops : 1; // valid only when the parent widget was hidden
bool hasQuit : 1;
};
@@ -92,7 +91,7 @@
void KSystemTrayIcon::init( QWidget* parent )
{
d->menu = new KMenu( parent );
- d->menu->addTitle( qApp->windowIcon(), KGlobal::caption() );
+ d->titleAction = d->menu->addTitle( qApp->windowIcon(), KGlobal::caption() );
d->menu->setTitle( KGlobal::mainComponent().aboutData()->programName() );
connect( d->menu, SIGNAL( aboutToShow() ), this, SLOT( contextMenuAboutToShow() \
) ); setContextMenu( d->menu );
@@ -305,5 +304,17 @@
return true;
}
+void KSystemTrayIcon::setContextMenuTitle(QAction *action)
+{
+ // can never be null, and is always the requsted type, so no need to do null \
checks after casts. + QToolButton *button = \
static_cast<QToolButton*>((static_cast<QWidgetAction*>(d->titleAction))->defaultWidget());
+ button->setDefaultAction(action);
+}
+
+QAction *KSystemTrayIcon::contextMenuTitle() const
+{
+ QToolButton *button = \
static_cast<QToolButton*>((static_cast<QWidgetAction*>(d->titleAction))->defaultWidget());
+ return button->defaultAction();
+}
+
#include "ksystemtrayicon.moc"
-
--- trunk/KDE/kdelibs/kdeui/util/ksystemtrayicon.h #788540:788541
@@ -25,13 +25,14 @@
class KActionCollection;
class KSystemTrayIconPrivate;
+class QAction;
/**
* \brief %KDE System Tray Window class
*
* This class implements system tray windows.
*
- * A tray window is a small window (typically 24x24 pixel) that docks
+ * A tray window is a small window (typically 22x22 pixel) that docks
* into the system tray in the desktop panel. It usually displays an
* icon or an animated icon there. The icon represents
* the application, similar to a taskbar button, but consumes less
@@ -76,7 +77,7 @@
*/
explicit KSystemTrayIcon( const QIcon& icon, QWidget* parent = 0 );
- /*
+ /**
Destructor
*/
~KSystemTrayIcon();
@@ -108,6 +109,24 @@
*/
static QIcon loadIcon(const QString &icon, const KComponentData &componentData = \
KGlobal::mainComponent());
+ /**
+ * Sets the context menu title action to @p action.
+ * The following code shows how to change the current title.
+ * <code>
+ * QAction *titleAction = contextMenuTitle();
+ * titleAction->setText("New Title");
+ * setContextMenuTitle(titleAction);
+ * </code>
+ * @since 4.1
+ */
+ void setContextMenuTitle(QAction *action);
+
+ /**
+ * Returns the context menu title action.
+ * @since 4.1
+ */
+ QAction *contextMenuTitle() const;
+
Q_SIGNALS:
/**
* Emitted when quit is selected in the menu. If you want to perform any other
--- trunk/KDE/kdelibs/kdeui/widgets/kmenu.cpp #788540:788541
@@ -32,6 +32,7 @@
#include <QtGui/QLabel>
#include <QtGui/QPainter>
#include <QtGui/QStyle>
+#include <QtGui/QToolButton>
#include <QtGui/QWidgetAction>
#include <kdebug.h>
@@ -128,41 +129,25 @@
QAction* KMenu::addTitle(const QString &text, QAction* before)
{
- QWidgetAction* action = new QWidgetAction(this);
- action->setEnabled(false);
- QLabel* label = new QLabel(this);
- action->setDefaultWidget(label);
- label->setFrameShape(QFrame::Box);
- label->setText(text);
- QFont f = label->font();
- f.setBold(true);
- label->setFont(f);
- insertAction(before, action);
- return action;
+ return addTitle(QIcon(), text, before);
}
QAction* KMenu::addTitle(const QIcon &icon, const QString &text, QAction* before)
{
- QWidgetAction* action = new QWidgetAction(this);
- action->setEnabled(false);
- QFrame *hbox = new QFrame( this );
- QHBoxLayout *layout = new QHBoxLayout( hbox );
- layout->setMargin( 3 );
- layout->setSpacing( 5 );
- QLabel* pix_label = new QLabel(hbox);
- layout->insertWidget( -1, pix_label, 0 );
- int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
- pix_label->setPixmap(icon.pixmap(QSize(iconSize, iconSize)));
+ QAction *buttonAction = new QAction(this);
+ QFont font = buttonAction->font();
+ font.setBold(true);
+ buttonAction->setFont(font);
+ buttonAction->setText(text);
+ buttonAction->setIcon(icon);
- QLabel *label = new QLabel( hbox );
- layout->insertWidget( -1, label, 20 );
- action->setDefaultWidget(hbox);
- hbox->setFrameShape(QFrame::Box);
- label->setText(text);
+ QWidgetAction *action = new QWidgetAction(this);
+ QToolButton *titleButton = new QToolButton(this);
+ titleButton->setDefaultAction(buttonAction);
+ titleButton->setDown(true); // prevent hover style changes in some styles
+ titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ action->setDefaultWidget(titleButton);
- QFont f = label->font();
- f.setBold(true);
- label->setFont(f);
insertAction(before, action);
return action;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic