2 This is the new kwindecoration kcontrol module
4 Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
6 Karol Szwed <gallium@kde.org>
9 Supports new kwin configuration plugins, and titlebar button position
10 modification via dnd interface.
12 Based on original "kwintheme" (Window Borders)
13 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 #include <QDragLeaveEvent>
39 #include <QDragMoveEvent>
42 #include <QResizeEvent>
43 #include <QVBoxLayout>
44 #include <QDragEnterEvent>
45 #include <QMouseEvent>
51 #include <kglobalsettings.h>
53 #include <kdecorationfactory.h>
59 #define BUTTONDRAGMIMETYPE "application/x-kde_kwindecoration_buttons"
60 ButtonDrag::ButtonDrag( Button btn
, QWidget
* parent
, const char* name
)
61 : Q3StoredDrag( BUTTONDRAGMIMETYPE
, parent
, name
)
64 QDataStream
stream(&data
, QIODevice::WriteOnly
);
67 stream
<< btn
.type
.unicode();
68 stream
<< (int) btn
.duplicate
;
69 stream
<< (int) btn
.supported
;
70 setEncodedData( data
);
74 bool ButtonDrag::canDecode( QDropEvent
* e
)
76 return e
->provides( BUTTONDRAGMIMETYPE
);
79 bool ButtonDrag::decode( QDropEvent
* e
, Button
& btn
)
81 QByteArray data
= e
->mimeData()->data( BUTTONDRAGMIMETYPE
);
85 QDataStream
stream(data
);
90 btn
.type
= QChar(type
);
93 btn
.duplicate
= duplicate
;
96 btn
.supported
= supported
;
107 Button::Button(const QString
& n
, const QBitmap
& i
, QChar t
, bool d
, bool s
)
120 // helper function to deal with the Button's bitmaps more easily...
121 QPixmap
bitmapPixmap(const QBitmap
& bm
, const QColor
& color
)
123 QPixmap
pm(bm
.size() );
127 p
.drawPixmap(0,0,bm
);
133 ButtonSource::ButtonSource(QWidget
*parent
)
136 setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Expanding
);
138 setResizeMode(Q3ListView::AllColumns
);
139 setDragEnabled(true);
140 setAcceptDrops(true);
141 setDropVisualizer(false);
143 header()->setClickEnabled(false);
146 addColumn(i18n("Buttons") );
149 ButtonSource::~ButtonSource()
153 QSize
ButtonSource::sizeHint() const
155 // make the sizeHint height a bit smaller than the one of QListView...
157 if ( cachedSizeHint().isValid() )
158 return cachedSizeHint();
162 QSize
s( header()->sizeHint() );
164 if ( verticalScrollBar()->isVisible() )
165 s
.setWidth( s
.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent
) );
166 s
+= QSize(frameWidth()*2,frameWidth()*2);
168 // size hint: 4 lines of text...
169 s
.setHeight( s
.height() + fontMetrics().lineSpacing()*3 );
171 setCachedSizeHint( s
);
176 void ButtonSource::hideAllButtons()
178 Q3ListViewItemIterator
it(this);
179 while (it
.current() ) {
180 it
.current()->setVisible(false);
185 void ButtonSource::showAllButtons()
187 Q3ListViewItemIterator
it(this);
188 while (it
.current() ) {
189 it
.current()->setVisible(true);
194 void ButtonSource::showButton( QChar btn
)
196 Q3ListViewItemIterator
it(this);
197 while (it
.current() ) {
198 ButtonSourceItem
*item
= dynamic_cast<ButtonSourceItem
*>(it
.current() );
199 if (item
&& item
->button().type
== btn
) {
200 it
.current()->setVisible(true);
207 void ButtonSource::hideButton( QChar btn
)
209 Q3ListViewItemIterator
it(this);
210 while (it
.current() ) {
211 ButtonSourceItem
*item
= dynamic_cast<ButtonSourceItem
*>(it
.current() );
212 if (item
&& item
->button().type
== btn
&& !item
->button().duplicate
) {
213 it
.current()->setVisible(false);
220 bool ButtonSource::acceptDrag(QDropEvent
* e
) const
222 return acceptDrops() && ButtonDrag::canDecode(e
);
225 Q3DragObject
*ButtonSource::dragObject()
227 ButtonSourceItem
*i
= dynamic_cast<ButtonSourceItem
*>(selectedItem() );
230 ButtonDrag
*bd
= new ButtonDrag(i
->button(), viewport(), "button_drag");
231 bd
->setPixmap(bitmapPixmap(i
->button().icon
, palette().color( QPalette::Foreground
)));
238 ButtonDropSiteItem::ButtonDropSiteItem(const Button
& btn
)
243 ButtonDropSiteItem::~ButtonDropSiteItem()
247 Button
ButtonDropSiteItem::button()
252 int ButtonDropSiteItem::width()
254 // return m_button.icon.width();
258 int ButtonDropSiteItem::height()
260 // return m_button.icon.height();
264 void ButtonDropSiteItem::draw(QPainter
*p
, const QPalette
& cg
, const QRect
&r
)
266 // p->fillRect(r, cg.base() );
267 if (m_button
.supported
)
268 p
->setPen(cg
.color(QPalette::Foreground
) );
270 p
->setPen( cg
.color(QPalette::Mid
) );
271 QBitmap
&i
= m_button
.icon
;
272 p
->drawPixmap(r
.left()+(r
.width()-i
.width())/2, r
.top()+(r
.height()-i
.height())/2, i
);
276 ButtonDropSite::ButtonDropSite( QWidget
* parent
, const char* name
)
280 setObjectName( name
);
281 setAcceptDrops( true );
282 setFrameShape( WinPanel
);
283 setFrameShadow( Raised
);
284 setMinimumHeight( 26 );
285 setMaximumHeight( 26 );
286 setMinimumWidth( 250 ); // Ensure buttons will fit
289 ButtonDropSite::~ButtonDropSite()
295 void ButtonDropSite::clearLeft()
297 while (!buttonsLeft
.isEmpty() ) {
298 ButtonDropSiteItem
*item
= buttonsLeft
.first();
299 if (removeButton(item
) ) {
300 emit
buttonRemoved(item
->button().type
);
306 void ButtonDropSite::clearRight()
308 while (!buttonsRight
.isEmpty() ) {
309 ButtonDropSiteItem
*item
= buttonsRight
.first();
310 if (removeButton(item
) ) {
311 emit
buttonRemoved(item
->button().type
);
317 void ButtonDropSite::dragMoveEvent( QDragMoveEvent
* e
)
320 if (leftDropArea().contains(p
) || rightDropArea().contains(p
) || buttonAt(p
) ) {
323 // 2 pixel wide drop visualizer...
324 QRect r
= contentsRect();
326 if (leftDropArea().contains(p
) ) {
327 x
= leftDropArea().left();
328 } else if (rightDropArea().contains(p
) ) {
329 x
= rightDropArea().right()+1;
331 ButtonDropSiteItem
*item
= buttonAt(p
);
333 if (p
.x() < item
->rect
.left()+item
->rect
.width()/2 ) {
334 x
= item
->rect
.left();
336 x
= item
->rect
.right()+1;
341 QRect
tmpRect(x
, r
.y(), 2, r
.height() );
342 if (tmpRect
!= m_oldDropVisualizer
) {
343 cleanDropVisualizer();
344 m_oldDropVisualizer
= tmpRect
;
352 cleanDropVisualizer();
356 void ButtonDropSite::cleanDropVisualizer()
358 if (m_oldDropVisualizer
.isValid())
360 QRect rect
= m_oldDropVisualizer
;
361 m_oldDropVisualizer
= QRect(); // rect is invalid
366 void ButtonDropSite::dragEnterEvent( QDragEnterEvent
* e
)
368 if ( ButtonDrag::canDecode( e
) )
372 void ButtonDropSite::dragLeaveEvent( QDragLeaveEvent
* /* e */ )
374 cleanDropVisualizer();
377 void ButtonDropSite::dropEvent( QDropEvent
* e
)
379 cleanDropVisualizer();
383 // collect information where to insert the dropped button
384 ButtonList
*buttonList
= 0;
387 if (leftDropArea().contains(p
) ) {
388 buttonList
= &buttonsLeft
;
389 buttonPosition
= buttonsLeft
.size();
390 } else if (rightDropArea().contains(p
) ) {
391 buttonList
= &buttonsRight
;
394 ButtonDropSiteItem
*aboveItem
= buttonAt(p
);
396 return; // invalid drop. hasn't occurred _over_ a button (or left/right dropArea), return...
399 if (!getItemPos(aboveItem
, buttonList
, pos
) ) {
400 // didn't find the aboveItem. unlikely to happen since buttonAt() already seems to have found
401 // something valid. anyway...
405 // got the list and the aboveItem position. now determine if the item should be inserted
406 // before aboveItem or after aboveItem.
407 QRect aboveItemRect
= aboveItem
->rect
;
408 if (!aboveItemRect
.isValid() )
411 if (p
.x() < aboveItemRect
.left()+aboveItemRect
.width()/2 ) {
412 // insert before the item
413 buttonPosition
= pos
;
415 buttonPosition
= pos
+ 1;
419 // know where to insert the button. now see if we can use an existing item (drag within the widget = move)
420 // orneed to create a new one
421 ButtonDropSiteItem
*buttonItem
= 0;
422 if (e
->source() == this && m_selected
) {
423 ButtonList
*oldList
= 0;
425 if (getItemPos(m_selected
, oldList
, oldPos
) ) {
426 if (oldPos
== buttonPosition
&& oldList
== buttonList
)
427 return; // button didn't change its position during the drag...
429 oldList
->removeAt(oldPos
);
430 buttonItem
= m_selected
;
432 // If we're inserting to the right of oldPos, in the same list,
433 // better adjust the index..
434 if (buttonList
== oldList
&& buttonPosition
> oldPos
)
437 return; // m_selected not found, return...
440 // create new button from the drop object...
442 if (ButtonDrag::decode(e
, btn
) ) {
443 buttonItem
= new ButtonDropSiteItem(btn
);
445 return; // something has gone wrong while we were trying to decode the drop event
449 // now the item can actually be inserted into the list! :)
450 (*buttonList
).insert(buttonPosition
, buttonItem
);
451 emit
buttonAdded(buttonItem
->button().type
);
453 recalcItemGeometry();
457 bool ButtonDropSite::getItemPos(ButtonDropSiteItem
*item
, ButtonList
* &list
, int &pos
)
462 pos
= buttonsLeft
.indexOf(item
); // try the left list first...
468 pos
= buttonsRight
.indexOf(item
); // try the right list...
470 list
= &buttonsRight
;
479 QRect
ButtonDropSite::leftDropArea()
481 // return a 10 pixel drop area...
482 QRect r
= contentsRect();
484 int leftButtonsWidth
= calcButtonListWidth(buttonsLeft
);
485 return QRect(r
.left()+leftButtonsWidth
, r
.top(), 10, r
.height() );
488 QRect
ButtonDropSite::rightDropArea()
490 // return a 10 pixel drop area...
491 QRect r
= contentsRect();
493 int rightButtonsWidth
= calcButtonListWidth(buttonsRight
);
494 return QRect(r
.right()-rightButtonsWidth
-10, r
.top(), 10, r
.height() );
497 void ButtonDropSite::mousePressEvent( QMouseEvent
* e
)
499 // TODO: only start the real drag after some drag distance
500 m_selected
= buttonAt(e
->pos() );
502 ButtonDrag
*bd
= new ButtonDrag(m_selected
->button(), this);
503 bd
->setPixmap(bitmapPixmap(m_selected
->button().icon
, palette().color( QPalette::Foreground
) ) );
508 void ButtonDropSite::resizeEvent(QResizeEvent
*)
510 recalcItemGeometry();
513 void ButtonDropSite::recalcItemGeometry()
515 QRect r
= contentsRect();
517 // update the geometry of the items in the left button list
518 int offset
= r
.left();
519 for (ButtonList::const_iterator it
= buttonsLeft
.constBegin(); it
!= buttonsLeft
.constEnd(); ++it
) {
520 int w
= (*it
)->width();
521 (*it
)->rect
= QRect(offset
, r
.top(), w
, (*it
)->height() );
525 // the right button list...
526 offset
= r
.right() - calcButtonListWidth(buttonsRight
);
527 for (ButtonList::const_iterator it
= buttonsRight
.constBegin(); it
!= buttonsRight
.constEnd(); ++it
) {
528 int w
= (*it
)->width();
529 (*it
)->rect
= QRect(offset
, r
.top(), w
, (*it
)->height() );
534 ButtonDropSiteItem
*ButtonDropSite::buttonAt(QPoint p
) {
535 // try to find the item in the left button list
536 for (ButtonList::const_iterator it
= buttonsLeft
.constBegin(); it
!= buttonsLeft
.constEnd(); ++it
) {
537 if ( (*it
)->rect
.contains(p
) ) {
542 // try to find the item in the right button list
543 for (ButtonList::const_iterator it
= buttonsRight
.constBegin(); it
!= buttonsRight
.constEnd(); ++it
) {
544 if ( (*it
)->rect
.contains(p
) ) {
552 bool ButtonDropSite::removeButton(ButtonDropSiteItem
*item
) {
556 // try to remove the item from the left button list
557 if (buttonsLeft
.removeAll(item
) >= 1) {
561 // try to remove the item from the right button list
562 if (buttonsRight
.removeAll(item
) >= 1) {
569 int ButtonDropSite::calcButtonListWidth(const ButtonList
& btns
)
572 for (ButtonList::const_iterator it
= btns
.constBegin(); it
!= btns
.constEnd(); ++it
) {
579 bool ButtonDropSite::removeSelectedButton()
581 bool succ
= removeButton(m_selected
);
583 emit
buttonRemoved(m_selected
->button().type
);
587 recalcItemGeometry();
588 update(); // repaint...
594 void ButtonDropSite::drawButtonList(QPainter
*p
, const ButtonList
& btns
, int offset
)
596 for (ButtonList::const_iterator it
= btns
.constBegin(); it
!= btns
.constEnd(); ++it
) {
597 QRect itemRect
= (*it
)->rect
;
598 if (itemRect
.isValid() ) {
599 (*it
)->draw(p
, palette(), itemRect
);
601 offset
+= (*it
)->width();
605 void ButtonDropSite::paintEvent( QPaintEvent
* /*pe*/ )
608 int leftoffset
= calcButtonListWidth( buttonsLeft
);
609 int rightoffset
= calcButtonListWidth( buttonsRight
);
612 QRect r
= contentsRect();
615 r
.translate(1 + leftoffset
, 1);
616 r
.setWidth( r
.width() - 2 - leftoffset
- rightoffset
);
617 r
.setHeight( r
.height() - 2 );
619 drawButtonList( &p
, buttonsLeft
, offset
);
621 QColor
c1( 0x0A, 0x5F, 0x89 ); // KDE 2 titlebar default colour
623 p
.setPen( Qt::white
);
624 p
.setFont( QFont( KGlobalSettings::generalFont().family(), 12, QFont::Bold
) );
625 p
.drawText( r
, Qt::AlignLeft
| Qt::AlignVCenter
, i18n("KDE") );
627 offset
= geometry().width() - 3 - rightoffset
;
628 drawButtonList( &p
, buttonsRight
, offset
);
630 if (m_oldDropVisualizer
.isValid() )
632 p
.fillRect(m_oldDropVisualizer
, Qt::Dense4Pattern
);
636 ButtonSourceItem::ButtonSourceItem(Q3ListView
* parent
, const Button
& btn
)
637 : Q3ListViewItem(parent
),
644 ButtonSourceItem::~ButtonSourceItem()
648 void ButtonSourceItem::paintCell(QPainter
*p
, const QPalette
&cg
, int column
, int width
, int align
)
650 // we need the color group cg, so to the work here, not in setButton...
652 if (m_button
.supported
) {
653 setPixmap(0, bitmapPixmap(m_button
.icon
, cg
.color( QPalette::Foreground
) ) );
655 setPixmap(0, bitmapPixmap(m_button
.icon
, cg
.color( QPalette::Mid
) ) );
660 if (m_button
.supported
) {
661 Q3ListViewItem::paintCell(p
,cg
,column
,width
,align
);
663 // grey out unsupported buttons
665 cg2
.setColor(QPalette::Text
, cg
.color(QPalette::Mid
) );
666 Q3ListViewItem::paintCell(p
,cg2
,column
,width
,align
);
670 void ButtonSourceItem::setButton(const Button
& btn
)
673 m_dirty
= true; // update the pixmap when in paintCell()...
675 setText(0, btn
.name
);
677 setText(0, i18n("%1 (unavailable)", btn
.name
) );
681 Button
ButtonSourceItem::button() const
687 ButtonPositionWidget::ButtonPositionWidget(QWidget
*parent
, const char* name
)
691 setObjectName( name
);
693 QVBoxLayout
*layout
= new QVBoxLayout(this);
694 layout
->setMargin(0);
695 layout
->setSpacing(KDialog::spacingHint());
696 setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Maximum
);
698 QLabel
* label
= new QLabel( this );
699 m_dropSite
= new ButtonDropSite( this );
700 label
->setWordWrap( true );
701 label
->setText( i18n( "To add or remove titlebar buttons, simply <i>drag</i> items "
702 "between the available item list and the titlebar preview. Similarly, "
703 "drag items within the titlebar preview to re-position them.") );
704 m_buttonSource
= new ButtonSource(this);
705 m_buttonSource
->setObjectName("button_source");
707 layout
->addWidget(label
);
708 layout
->addWidget(m_dropSite
);
709 layout
->addWidget(m_buttonSource
);
711 connect( m_dropSite
, SIGNAL(buttonAdded(QChar
)), m_buttonSource
, SLOT(hideButton(QChar
)) );
712 connect( m_dropSite
, SIGNAL(buttonRemoved(QChar
)), m_buttonSource
, SLOT(showButton(QChar
)) );
713 connect( m_buttonSource
, SIGNAL(dropped(QDropEvent
*, Q3ListViewItem
*)), m_dropSite
, SLOT(removeSelectedButton()) );
715 connect( m_dropSite
, SIGNAL(changed()), SIGNAL(changed()) );
717 // insert all possible buttons into the source (backwards to keep the preferred order...)
719 new ButtonSourceItem(m_buttonSource
, getButton('R', dummy
) );
720 new ButtonSourceItem(m_buttonSource
, getButton('L', dummy
) );
721 new ButtonSourceItem(m_buttonSource
, getButton('B', dummy
) );
722 new ButtonSourceItem(m_buttonSource
, getButton('F', dummy
) );
723 new ButtonSourceItem(m_buttonSource
, getButton('X', dummy
) );
724 new ButtonSourceItem(m_buttonSource
, getButton('A', dummy
) );
725 new ButtonSourceItem(m_buttonSource
, getButton('I', dummy
) );
726 new ButtonSourceItem(m_buttonSource
, getButton('H', dummy
) );
727 new ButtonSourceItem(m_buttonSource
, getButton('S', dummy
) );
728 new ButtonSourceItem(m_buttonSource
, getButton('M', dummy
) );
729 new ButtonSourceItem(m_buttonSource
, getButton('_', dummy
) );
732 ButtonPositionWidget::~ButtonPositionWidget()
736 void ButtonPositionWidget::setDecorationFactory(KDecorationFactory
*factory
)
743 // get the list of supported buttons
744 if (m_factory
->supports(KDecorationDefines::AbilityAnnounceButtons
) ) {
745 QString supportedButtons
;
747 if (m_factory
->supports(KDecorationDefines::AbilityButtonMenu
) )
748 supportedButtons
.append('M');
749 if (m_factory
->supports(KDecorationDefines::AbilityButtonOnAllDesktops
) )
750 supportedButtons
.append('S');
751 if (m_factory
->supports(KDecorationDefines::AbilityButtonSpacer
) )
752 supportedButtons
.append('_');
753 if (m_factory
->supports(KDecorationDefines::AbilityButtonHelp
) )
754 supportedButtons
.append('H');
755 if (m_factory
->supports(KDecorationDefines::AbilityButtonMinimize
) )
756 supportedButtons
.append('I');
757 if (m_factory
->supports(KDecorationDefines::AbilityButtonMaximize
) )
758 supportedButtons
.append('A');
759 if (m_factory
->supports(KDecorationDefines::AbilityButtonClose
) )
760 supportedButtons
.append('X');
761 if (m_factory
->supports(KDecorationDefines::AbilityButtonAboveOthers
) )
762 supportedButtons
.append('F');
763 if (m_factory
->supports(KDecorationDefines::AbilityButtonBelowOthers
) )
764 supportedButtons
.append('B');
765 if (m_factory
->supports(KDecorationDefines::AbilityButtonShade
) )
766 supportedButtons
.append('L');
767 if (m_factory
->supports(KDecorationDefines::AbilityButtonResize
) )
768 supportedButtons
.append('R');
770 m_supportedButtons
= supportedButtons
;
772 // enable only buttons available before AbilityButton* introduction
773 m_supportedButtons
= "MSHIAX_";
776 // update the button lists...
777 // 1. set status on the source items...
778 Q3ListViewItemIterator
it(m_buttonSource
);
779 while (it
.current() ) {
780 ButtonSourceItem
*i
= dynamic_cast<ButtonSourceItem
*>(it
.current() );
782 Button b
= i
->button();
783 b
.supported
= m_supportedButtons
.contains(b
.type
);
788 // 2. rebuild the drop site items...
789 setButtonsLeft(buttonsLeft() );
790 setButtonsRight(buttonsRight() );
793 Button
ButtonPositionWidget::getButton(QChar type
, bool& success
) {
797 QBitmap bmp
= QBitmap::fromData(QSize( resize_width
, resize_height
), resize_bits
);
799 return Button(i18n("Resize"), bmp
, 'R', false, m_supportedButtons
.contains('R') );
800 } else if (type
== 'L') {
801 QBitmap bmp
= QBitmap::fromData(QSize( shade_width
, shade_height
), shade_bits
);
803 return Button(i18n("Shade"), bmp
, 'L', false, m_supportedButtons
.contains('L') );
804 } else if (type
== 'B') {
805 QBitmap bmp
= QBitmap::fromData(QSize( keepbelowothers_width
, keepbelowothers_height
), keepbelowothers_bits
);
807 return Button(i18n("Keep Below Others"), bmp
, 'B', false, m_supportedButtons
.contains('B') );
808 } else if (type
== 'F') {
809 QBitmap bmp
= QBitmap::fromData(QSize( keepaboveothers_width
, keepaboveothers_height
), keepaboveothers_bits
);
811 return Button(i18n("Keep Above Others"), bmp
, 'F', false, m_supportedButtons
.contains('F') );
812 } else if (type
== 'X') {
813 QBitmap bmp
= QBitmap::fromData(QSize( close_width
, close_height
), close_bits
);
815 return Button(i18n("Close"), bmp
, 'X', false, m_supportedButtons
.contains('X') );
816 } else if (type
== 'A') {
817 QBitmap bmp
= QBitmap::fromData(QSize( maximize_width
, maximize_height
), maximize_bits
);
819 return Button(i18n("Maximize"), bmp
, 'A', false, m_supportedButtons
.contains('A') );
820 } else if (type
== 'I') {
821 QBitmap bmp
= QBitmap::fromData(QSize( minimize_width
, minimize_height
), minimize_bits
);
823 return Button(i18n("Minimize"), bmp
, 'I', false, m_supportedButtons
.contains('I') );
824 } else if (type
== 'H') {
825 QBitmap bmp
= QBitmap::fromData(QSize( help_width
, help_height
), help_bits
);
827 return Button(i18n("Help"), bmp
, 'H', false, m_supportedButtons
.contains('H') );
828 } else if (type
== 'S') {
829 QBitmap bmp
= QBitmap::fromData(QSize( onalldesktops_width
, onalldesktops_height
), onalldesktops_bits
);
831 return Button(i18n("On All Desktops"), bmp
, 'S', false, m_supportedButtons
.contains('S') );
832 } else if (type
== 'M') {
833 QBitmap bmp
= QBitmap::fromData(QSize( menu_width
, menu_height
), menu_bits
);
835 return Button(i18n("Menu"), bmp
, 'M', false, m_supportedButtons
.contains('M') );
836 } else if (type
== '_') {
837 QBitmap bmp
= QBitmap::fromData(QSize( spacer_width
, spacer_height
), spacer_bits
);
839 return Button(i18n("--- spacer ---"), bmp
, '_', true, m_supportedButtons
.contains('_') );
846 QString
ButtonPositionWidget::buttonsLeft() const
848 ButtonList btns
= m_dropSite
->buttonsLeft
;
849 QString btnString
= "";
850 for (ButtonList::const_iterator it
= btns
.constBegin(); it
!= btns
.constEnd(); ++it
) {
851 btnString
.append( (*it
)->button().type
);
856 QString
ButtonPositionWidget::buttonsRight() const
858 ButtonList btns
= m_dropSite
->buttonsRight
;
859 QString btnString
= "";
860 for (ButtonList::const_iterator it
= btns
.constBegin(); it
!= btns
.constEnd(); ++it
) {
861 btnString
.append( (*it
)->button().type
);
866 void ButtonPositionWidget::setButtonsLeft(const QString
&buttons
)
868 // to keep the button lists consistent, first remove all left buttons, then add buttons again...
869 m_dropSite
->clearLeft();
871 for (int i
= 0; i
< buttons
.length(); ++i
) {
873 Button btn
= getButton(buttons
[i
], succ
);
875 m_dropSite
->buttonsLeft
.append(new ButtonDropSiteItem(btn
) );
876 m_buttonSource
->hideButton(btn
.type
);
879 m_dropSite
->recalcItemGeometry();
880 m_dropSite
->update();
883 void ButtonPositionWidget::setButtonsRight(const QString
&buttons
)
885 // to keep the button lists consistent, first remove all left buttons, then add buttons again...
886 m_dropSite
->clearRight();
888 for (int i
= 0; i
< buttons
.length(); ++i
) {
890 Button btn
= getButton(buttons
[i
], succ
);
892 m_dropSite
->buttonsRight
.append(new ButtonDropSiteItem(btn
) );
893 m_buttonSource
->hideButton(btn
.type
);
896 m_dropSite
->recalcItemGeometry();
897 m_dropSite
->update();
900 #include "buttons.moc"
902 // kate: space-indent off; tab-width 4;