[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Issues using KToolBarLabelAction
From: Albert Astals Cid <aacid () kde ! org>
Date: 2008-04-20 19:11:31
Message-ID: 200804202111.32918.aacid () kde ! org
[Download RAW message or body]
Moving to kde-core-devel as it's a bug in kde core libraries, please only
answer to k-c-d
A Diumenge 20 Abril 2008, David Boosalis va escriure:
> I wanted to put a label in a KToolBar. I reached for the
> KToolBarLabelAction class to do this. Maybe I just don't get it or maybe
> the code below shows a bug. Any advise appreciated.
Yeah it seems like a bug to me too, the attached patch #1 fixes the problem
for me.
Patch #2 fixes the fact that if you change the action text after showing the
toolbar the label is not updated.
Ok to commit both patches?
Albert
["ktoolbarlabelaction-1.patch" (text/x-diff)]
Index: ktoolbarlabelaction.cpp
===================================================================
--- ktoolbarlabelaction.cpp (revision 798838)
+++ ktoolbarlabelaction.cpp (working copy)
@@ -103,6 +103,7 @@
newLabel->setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft) |
Qt::AlignVCenter );
newLabel->adjustSize();
+ newLabel->setText(text());
if ( d->buddy )
foreach ( QWidget* widget, d->buddy->associatedWidgets() )
["ktoolbarlabelaction-2.patch" (text/x-diff)]
--- ktoolbarlabelaction.cpp.old 2008-04-20 21:07:53.000000000 +0200
+++ ktoolbarlabelaction.cpp 2008-04-20 21:10:20.000000000 +0200
@@ -27,24 +27,23 @@
{
public:
QPointer<QAction> buddy;
- QString oldText;
+ QPointer<QLabel> label;
};
KToolBarLabelAction::KToolBarLabelAction(const QString &text, QObject *parent)
: KAction(text, parent),
d( new Private )
{
- d->oldText = KToolBarLabelAction::text();
+ d->label = NULL;
}
KToolBarLabelAction::KToolBarLabelAction(QAction* buddy, const QString &text, QObject *parent)
: KAction(text, parent),
d( new Private )
{
-
setBuddy( buddy );
- d->oldText = KToolBarLabelAction::text();
+ d->label = NULL;
}
KToolBarLabelAction::~KToolBarLabelAction()
@@ -79,9 +78,9 @@
bool KToolBarLabelAction::event( QEvent *event )
{
if ( event->type() == QEvent::ActionChanged ) {
- if ( text() != d->oldText ) {
+ if ( d->label && text() != d->label->text() ) {
emit textChanged( text() );
- d->oldText = text();
+ d->label->setText(text());
}
}
@@ -93,27 +92,31 @@
QToolBar *parent = qobject_cast<QToolBar *>(_parent);
if (!parent)
return KAction::createWidget(_parent);
- QLabel* newLabel = new QLabel( parent );
+ if (d->label != NULL) {
+ d->label = new QLabel( parent );
- /**
- * These lines were copied from Konqueror's KonqDraggableLabel class in
- * konq_misc.cc
- */
- newLabel->setBackgroundRole( QPalette::Button );
- newLabel->setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft) |
- Qt::AlignVCenter );
- newLabel->adjustSize();
- newLabel->setText(text());
-
- if ( d->buddy )
- foreach ( QWidget* widget, d->buddy->associatedWidgets() )
- if ( QToolBar* toolBar = qobject_cast<QToolBar*>( widget ) ) {
- QWidget* newBuddy = toolBar->widgetForAction( d->buddy );
- newLabel->setBuddy( newBuddy );
- break;
+ /**
+ * These lines were copied from Konqueror's KonqDraggableLabel class in
+ * konq_misc.cc
+ */
+ d->label->setBackgroundRole( QPalette::Button );
+ d->label->setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft) |
+ Qt::AlignVCenter );
+ d->label->adjustSize();
+ d->label->setText(text());
+
+ if ( d->buddy ) {
+ foreach ( QWidget* widget, d->buddy->associatedWidgets() ) {
+ if ( QToolBar* toolBar = qobject_cast<QToolBar*>( widget ) ) {
+ QWidget* newBuddy = toolBar->widgetForAction( d->buddy );
+ d->label->setBuddy( newBuddy );
+ break;
+ }
}
+ }
+ }
- return newLabel;
+ return d->label;
}
#include "ktoolbarlabelaction.moc"
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic