add more spacing
[personal-kdebase.git] / workspace / kwin / kcmkwin / kwindecoration / buttons.cpp
blob2ace9ae2d6ba50b02e59855caf79fa9fb8f57e33
1 /*
2 This is the new kwindecoration kcontrol module
4 Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
5 Copyright (c) 2001
6 Karol Szwed <gallium@kde.org>
7 http://gallium.n3.net/
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.
31 #include <q3header.h>
32 #include <QPainter>
33 #include <QLabel>
34 #include <QLayout>
35 #include <QStyle>
36 //Added by qt3to4:
37 #include <QPixmap>
38 #include <QDragLeaveEvent>
39 #include <QDragMoveEvent>
40 #include <QDropEvent>
41 #include <QFrame>
42 #include <QResizeEvent>
43 #include <QVBoxLayout>
44 #include <QDragEnterEvent>
45 #include <QMouseEvent>
47 #include <kdebug.h>
49 #include <kdialog.h>
50 #include <klocale.h>
51 #include <kglobalsettings.h>
53 #include <kdecorationfactory.h>
55 #include "buttons.h"
56 #include "pixmaps.h"
59 #define BUTTONDRAGMIMETYPE "application/x-kde_kwindecoration_buttons"
60 ButtonDrag::ButtonDrag( Button btn, QWidget* parent, const char* name)
61 : Q3StoredDrag( BUTTONDRAGMIMETYPE, parent, name)
63 QByteArray data;
64 QDataStream stream(&data, QIODevice::WriteOnly);
65 stream << btn.name;
66 stream << btn.icon;
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 );
82 if ( data.size() )
84 e->accept();
85 QDataStream stream(data);
86 stream >> btn.name;
87 stream >> btn.icon;
88 ushort type;
89 stream >> type;
90 btn.type = QChar(type);
91 int duplicate;
92 stream >> duplicate;
93 btn.duplicate = duplicate;
94 int supported;
95 stream >> supported;
96 btn.supported = supported;
97 return true;
99 return false;
103 Button::Button()
107 Button::Button(const QString& n, const QBitmap& i, QChar t, bool d, bool s)
108 : name(n),
109 icon(i),
110 type(t),
111 duplicate(d),
112 supported(s)
116 Button::~Button()
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() );
124 pm.setMask(bm);
125 QPainter p(&pm);
126 p.setPen(color);
127 p.drawPixmap(0,0,bm);
128 p.end();
129 return pm;
133 ButtonSource::ButtonSource(QWidget *parent)
134 : K3ListView(parent)
136 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
138 setResizeMode(Q3ListView::AllColumns);
139 setDragEnabled(true);
140 setAcceptDrops(true);
141 setDropVisualizer(false);
142 setSorting(-1);
143 header()->setClickEnabled(false);
144 header()->hide();
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();
160 ensurePolished();
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 );
173 return s;
176 void ButtonSource::hideAllButtons()
178 Q3ListViewItemIterator it(this);
179 while (it.current() ) {
180 it.current()->setVisible(false);
181 ++it;
185 void ButtonSource::showAllButtons()
187 Q3ListViewItemIterator it(this);
188 while (it.current() ) {
189 it.current()->setVisible(true);
190 ++it;
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);
201 return;
203 ++it;
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);
214 return;
216 ++it;
220 bool ButtonSource::acceptDrag(QDropEvent* e) const
222 return acceptDrops() && ButtonDrag::canDecode(e);
225 Q3DragObject *ButtonSource::dragObject()
227 ButtonSourceItem *i = dynamic_cast<ButtonSourceItem*>(selectedItem() );
229 if (i) {
230 ButtonDrag *bd = new ButtonDrag(i->button(), viewport(), "button_drag");
231 bd->setPixmap(bitmapPixmap(i->button().icon, palette().color( QPalette::Foreground )));
232 return bd;
235 return 0;
238 ButtonDropSiteItem::ButtonDropSiteItem(const Button& btn)
239 : m_button(btn)
243 ButtonDropSiteItem::~ButtonDropSiteItem()
247 Button ButtonDropSiteItem::button()
249 return m_button;
252 int ButtonDropSiteItem::width()
254 // return m_button.icon.width();
255 return 20;
258 int ButtonDropSiteItem::height()
260 // return m_button.icon.height();
261 return 20;
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) );
269 else
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 )
277 : QFrame( parent ),
278 m_selected(0)
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()
291 clearLeft();
292 clearRight();
295 void ButtonDropSite::clearLeft()
297 while (!buttonsLeft.isEmpty() ) {
298 ButtonDropSiteItem *item = buttonsLeft.first();
299 if (removeButton(item) ) {
300 emit buttonRemoved(item->button().type);
301 delete item;
306 void ButtonDropSite::clearRight()
308 while (!buttonsRight.isEmpty() ) {
309 ButtonDropSiteItem *item = buttonsRight.first();
310 if (removeButton(item) ) {
311 emit buttonRemoved(item->button().type);
312 delete item;
317 void ButtonDropSite::dragMoveEvent( QDragMoveEvent* e )
319 QPoint p = e->pos();
320 if (leftDropArea().contains(p) || rightDropArea().contains(p) || buttonAt(p) ) {
321 e->accept();
323 // 2 pixel wide drop visualizer...
324 QRect r = contentsRect();
325 int x = -1;
326 if (leftDropArea().contains(p) ) {
327 x = leftDropArea().left();
328 } else if (rightDropArea().contains(p) ) {
329 x = rightDropArea().right()+1;
330 } else {
331 ButtonDropSiteItem *item = buttonAt(p);
332 if (item) {
333 if (p.x() < item->rect.left()+item->rect.width()/2 ) {
334 x = item->rect.left();
335 } else {
336 x = item->rect.right()+1;
340 if (x != -1) {
341 QRect tmpRect(x, r.y(), 2, r.height() );
342 if (tmpRect != m_oldDropVisualizer) {
343 cleanDropVisualizer();
344 m_oldDropVisualizer = tmpRect;
345 update(tmpRect);
349 } else {
350 e->ignore();
352 cleanDropVisualizer();
356 void ButtonDropSite::cleanDropVisualizer()
358 if (m_oldDropVisualizer.isValid())
360 QRect rect = m_oldDropVisualizer;
361 m_oldDropVisualizer = QRect(); // rect is invalid
362 update(rect);
366 void ButtonDropSite::dragEnterEvent( QDragEnterEvent* e )
368 if ( ButtonDrag::canDecode( e ) )
369 e->accept();
372 void ButtonDropSite::dragLeaveEvent( QDragLeaveEvent* /* e */ )
374 cleanDropVisualizer();
377 void ButtonDropSite::dropEvent( QDropEvent* e )
379 cleanDropVisualizer();
381 QPoint p = e->pos();
383 // collect information where to insert the dropped button
384 ButtonList *buttonList = 0;
385 int buttonPosition;
387 if (leftDropArea().contains(p) ) {
388 buttonList = &buttonsLeft;
389 buttonPosition = buttonsLeft.size();
390 } else if (rightDropArea().contains(p) ) {
391 buttonList = &buttonsRight;
392 buttonPosition = 0;
393 } else {
394 ButtonDropSiteItem *aboveItem = buttonAt(p);
395 if (!aboveItem)
396 return; // invalid drop. hasn't occurred _over_ a button (or left/right dropArea), return...
398 int pos;
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...
402 return;
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() )
409 return;
411 if (p.x() < aboveItemRect.left()+aboveItemRect.width()/2 ) {
412 // insert before the item
413 buttonPosition = pos;
414 } else {
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;
424 int oldPos;
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)
435 --buttonPosition;
436 } else {
437 return; // m_selected not found, return...
439 } else {
440 // create new button from the drop object...
441 Button btn;
442 if (ButtonDrag::decode(e, btn) ) {
443 buttonItem = new ButtonDropSiteItem(btn);
444 } else {
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);
452 emit changed();
453 recalcItemGeometry();
454 update();
457 bool ButtonDropSite::getItemPos(ButtonDropSiteItem *item, ButtonList* &list, int &pos)
459 if (!item)
460 return false;
462 pos = buttonsLeft.indexOf(item); // try the left list first...
463 if (pos >= 0) {
464 list = &buttonsLeft;
465 return true;
468 pos = buttonsRight.indexOf(item); // try the right list...
469 if (pos >= 0) {
470 list = &buttonsRight;
471 return true;
474 list = 0;
475 pos = -1;
476 return false;
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() );
501 if (m_selected) {
502 ButtonDrag *bd = new ButtonDrag(m_selected->button(), this);
503 bd->setPixmap(bitmapPixmap(m_selected->button().icon, palette().color( QPalette::Foreground ) ) );
504 bd->dragMove();
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() );
522 offset += w;
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() );
530 offset += w;
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) ) {
538 return *it;
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) ) {
545 return *it;
549 return 0;
552 bool ButtonDropSite::removeButton(ButtonDropSiteItem *item) {
553 if (!item)
554 return false;
556 // try to remove the item from the left button list
557 if (buttonsLeft.removeAll(item) >= 1) {
558 return true;
561 // try to remove the item from the right button list
562 if (buttonsRight.removeAll(item) >= 1) {
563 return true;
566 return false;
569 int ButtonDropSite::calcButtonListWidth(const ButtonList& btns)
571 int w = 0;
572 for (ButtonList::const_iterator it = btns.constBegin(); it != btns.constEnd(); ++it) {
573 w += (*it)->width();
576 return w;
579 bool ButtonDropSite::removeSelectedButton()
581 bool succ = removeButton(m_selected);
582 if (succ) {
583 emit buttonRemoved(m_selected->button().type);
584 emit changed();
585 delete m_selected;
586 m_selected = 0;
587 recalcItemGeometry();
588 update(); // repaint...
591 return succ;
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*/ )
607 QPainter p( this );
608 int leftoffset = calcButtonListWidth( buttonsLeft );
609 int rightoffset = calcButtonListWidth( buttonsRight );
610 int offset = 3;
612 QRect r = contentsRect();
614 // Shrink by 1
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
622 p.fillRect( r, c1 );
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),
638 m_button(btn),
639 m_dirty(true)
641 setButton(btn);
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...
651 if (m_dirty) {
652 if (m_button.supported) {
653 setPixmap(0, bitmapPixmap(m_button.icon, cg.color( QPalette::Foreground ) ) );
654 } else {
655 setPixmap(0, bitmapPixmap(m_button.icon, cg.color( QPalette::Mid ) ) );
657 m_dirty = false;
660 if (m_button.supported) {
661 Q3ListViewItem::paintCell(p,cg,column,width,align);
662 } else {
663 // grey out unsupported buttons
664 QPalette cg2 = cg;
665 cg2.setColor(QPalette::Text, cg.color(QPalette::Mid) );
666 Q3ListViewItem::paintCell(p,cg2,column,width,align);
670 void ButtonSourceItem::setButton(const Button& btn)
672 m_button = btn;
673 m_dirty = true; // update the pixmap when in paintCell()...
674 if (btn.supported) {
675 setText(0, btn.name);
676 } else {
677 setText(0, i18n("%1 (unavailable)", btn.name) );
681 Button ButtonSourceItem::button() const
683 return m_button;
687 ButtonPositionWidget::ButtonPositionWidget(QWidget *parent, const char* name)
688 : QWidget(parent),
689 m_factory(0)
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...)
718 bool dummy;
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)
738 if (!factory)
739 return;
741 m_factory = 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;
771 } else {
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() );
781 if (i) {
782 Button b = i->button();
783 b.supported = m_supportedButtons.contains(b.type);
784 i->setButton(b);
786 ++it;
788 // 2. rebuild the drop site items...
789 setButtonsLeft(buttonsLeft() );
790 setButtonsRight(buttonsRight() );
793 Button ButtonPositionWidget::getButton(QChar type, bool& success) {
794 success = true;
796 if (type == 'R') {
797 QBitmap bmp = QBitmap::fromData(QSize( resize_width, resize_height ), resize_bits);
798 bmp.setMask(bmp);
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);
802 bmp.setMask(bmp);
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);
806 bmp.setMask(bmp);
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);
810 bmp.setMask(bmp);
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);
814 bmp.setMask(bmp);
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);
818 bmp.setMask(bmp);
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);
822 bmp.setMask(bmp);
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);
826 bmp.setMask(bmp);
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);
830 bmp.setMask(bmp);
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);
834 bmp.setMask(bmp);
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);
838 bmp.setMask(bmp);
839 return Button(i18n("--- spacer ---"), bmp, '_', true, m_supportedButtons.contains('_') );
840 } else {
841 success = false;
842 return Button();
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 );
853 return btnString;
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 );
863 return btnString;
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) {
872 bool succ = false;
873 Button btn = getButton(buttons[i], succ);
874 if (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) {
889 bool succ = false;
890 Button btn = getButton(buttons[i], succ);
891 if (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"
901 // vim: ts=4
902 // kate: space-indent off; tab-width 4;