2002-01-16 12:26:03 +00:00
|
|
|
/*
|
|
|
|
This is the new kwindecoration kcontrol module
|
|
|
|
|
2006-04-10 11:57:13 +00:00
|
|
|
Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
|
2002-01-16 12:26:03 +00:00
|
|
|
Copyright (c) 2001
|
|
|
|
Karol Szwed <gallium@kde.org>
|
|
|
|
http://gallium.n3.net/
|
|
|
|
|
|
|
|
Supports new kwin configuration plugins, and titlebar button position
|
|
|
|
modification via dnd interface.
|
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
Based on original "kwintheme" (Window Borders)
|
2002-01-16 12:26:03 +00:00
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
2003-09-19 11:14:41 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2005-10-03 15:54:58 +00:00
|
|
|
|
2003-09-19 11:14:41 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2005-10-03 15:54:58 +00:00
|
|
|
|
2003-09-19 11:14:41 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-12-21 06:45:09 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-09-19 11:14:41 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
*/
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <q3header.h>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QPainter>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLayout>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QStyle>
|
2005-07-28 14:59:42 +00:00
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QDragLeaveEvent>
|
|
|
|
#include <QDragMoveEvent>
|
|
|
|
#include <QDropEvent>
|
2005-11-30 21:17:50 +00:00
|
|
|
#include <QFrame>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QMouseEvent>
|
2004-12-09 21:33:16 +00:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
2004-12-03 22:23:20 +00:00
|
|
|
|
|
|
|
#include <kdialog.h>
|
2002-01-16 12:26:03 +00:00
|
|
|
#include <klocale.h>
|
2003-07-19 08:02:40 +00:00
|
|
|
#include <kglobalsettings.h>
|
2004-12-10 18:28:28 +00:00
|
|
|
|
|
|
|
#include <kdecorationfactory.h>
|
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
#include "buttons.h"
|
|
|
|
#include "pixmaps.h"
|
|
|
|
|
|
|
|
|
2004-12-03 20:31:03 +00:00
|
|
|
#define BUTTONDRAGMIMETYPE "application/x-kde_kwindecoration_buttons"
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonDrag::ButtonDrag( Button btn, QWidget* parent, const char* name)
|
2005-07-28 14:59:42 +00:00
|
|
|
: Q3StoredDrag( BUTTONDRAGMIMETYPE, parent, name)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
QByteArray data;
|
2005-07-28 14:59:42 +00:00
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
2004-12-09 21:33:16 +00:00
|
|
|
stream << btn.name;
|
|
|
|
stream << btn.icon;
|
|
|
|
stream << btn.type.unicode();
|
|
|
|
stream << (int) btn.duplicate;
|
|
|
|
stream << (int) btn.supported;
|
|
|
|
setEncodedData( data );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
bool ButtonDrag::canDecode( QDropEvent* e )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-03 20:31:03 +00:00
|
|
|
return e->provides( BUTTONDRAGMIMETYPE );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
bool ButtonDrag::decode( QDropEvent* e, Button& btn )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2006-04-12 15:13:31 +00:00
|
|
|
QByteArray data = e->mimeData()->data( BUTTONDRAGMIMETYPE );
|
2004-12-09 21:33:16 +00:00
|
|
|
if ( data.size() )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
e->accept();
|
2005-07-28 14:59:42 +00:00
|
|
|
QDataStream stream(data);
|
2004-12-09 21:33:16 +00:00
|
|
|
stream >> btn.name;
|
|
|
|
stream >> btn.icon;
|
|
|
|
ushort type;
|
|
|
|
stream >> type;
|
|
|
|
btn.type = QChar(type);
|
2004-12-10 15:36:46 +00:00
|
|
|
int duplicate;
|
|
|
|
stream >> duplicate;
|
|
|
|
btn.duplicate = duplicate;
|
|
|
|
int supported;
|
|
|
|
stream >> supported;
|
|
|
|
btn.supported = supported;
|
2006-02-19 01:33:48 +00:00
|
|
|
return true;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
2006-02-19 01:33:48 +00:00
|
|
|
return false;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
Button::Button()
|
|
|
|
{
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-10 17:58:37 +00:00
|
|
|
Button::Button(const QString& n, const QBitmap& i, QChar t, bool d, bool s)
|
2004-12-09 21:33:16 +00:00
|
|
|
: name(n),
|
|
|
|
icon(i),
|
|
|
|
type(t),
|
|
|
|
duplicate(d),
|
|
|
|
supported(s)
|
|
|
|
{
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
Button::~Button()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-10 17:58:37 +00:00
|
|
|
// helper function to deal with the Button's bitmaps more easily...
|
|
|
|
QPixmap bitmapPixmap(const QBitmap& bm, const QColor& color)
|
|
|
|
{
|
|
|
|
QPixmap pm(bm.size() );
|
|
|
|
pm.setMask(bm);
|
|
|
|
QPainter p(&pm);
|
|
|
|
p.setPen(color);
|
|
|
|
p.drawPixmap(0,0,bm);
|
|
|
|
p.end();
|
|
|
|
return pm;
|
|
|
|
}
|
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2005-10-03 15:54:58 +00:00
|
|
|
ButtonSource::ButtonSource(QWidget *parent)
|
2006-03-13 10:12:27 +00:00
|
|
|
: K3ListView(parent)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
setResizeMode(Q3ListView::AllColumns);
|
2004-12-09 21:33:16 +00:00
|
|
|
setDragEnabled(true);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setDropVisualizer(false);
|
|
|
|
setSorting(-1);
|
|
|
|
header()->setClickEnabled(false);
|
|
|
|
header()->hide();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
addColumn(i18n("Buttons") );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonSource::~ButtonSource()
|
|
|
|
{
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
QSize ButtonSource::sizeHint() const
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// make the sizeHint height a bit smaller than the one of QListView...
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
if ( cachedSizeHint().isValid() )
|
|
|
|
return cachedSizeHint();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
ensurePolished();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
QSize s( header()->sizeHint() );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
if ( verticalScrollBar()->isVisible() )
|
2005-07-28 14:59:42 +00:00
|
|
|
s.setWidth( s.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent) );
|
2004-12-09 21:33:16 +00:00
|
|
|
s += QSize(frameWidth()*2,frameWidth()*2);
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// size hint: 4 lines of text...
|
|
|
|
s.setHeight( s.height() + fontMetrics().lineSpacing()*3 );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
setCachedSizeHint( s );
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
void ButtonSource::hideAllButtons()
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItemIterator it(this);
|
2004-12-09 21:33:16 +00:00
|
|
|
while (it.current() ) {
|
|
|
|
it.current()->setVisible(false);
|
|
|
|
++it;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonSource::showAllButtons()
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItemIterator it(this);
|
2004-12-09 21:33:16 +00:00
|
|
|
while (it.current() ) {
|
|
|
|
it.current()->setVisible(true);
|
|
|
|
++it;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonSource::showButton( QChar btn )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItemIterator it(this);
|
2004-12-09 21:33:16 +00:00
|
|
|
while (it.current() ) {
|
|
|
|
ButtonSourceItem *item = dynamic_cast<ButtonSourceItem*>(it.current() );
|
|
|
|
if (item && item->button().type == btn) {
|
|
|
|
it.current()->setVisible(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++it;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonSource::hideButton( QChar btn )
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItemIterator it(this);
|
2004-12-09 21:33:16 +00:00
|
|
|
while (it.current() ) {
|
|
|
|
ButtonSourceItem *item = dynamic_cast<ButtonSourceItem*>(it.current() );
|
|
|
|
if (item && item->button().type == btn && !item->button().duplicate) {
|
|
|
|
it.current()->setVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++it;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
bool ButtonSource::acceptDrag(QDropEvent* e) const
|
|
|
|
{
|
|
|
|
return acceptDrops() && ButtonDrag::canDecode(e);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3DragObject *ButtonSource::dragObject()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonSourceItem *i = dynamic_cast<ButtonSourceItem*>(selectedItem() );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
if (i) {
|
|
|
|
ButtonDrag *bd = new ButtonDrag(i->button(), viewport(), "button_drag");
|
2006-04-12 15:13:31 +00:00
|
|
|
bd->setPixmap(bitmapPixmap(i->button().icon, palette().color( QPalette::Foreground )));
|
2004-12-09 21:33:16 +00:00
|
|
|
return bd;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonDropSiteItem::ButtonDropSiteItem(const Button& btn)
|
|
|
|
: m_button(btn)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonDropSiteItem::~ButtonDropSiteItem()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
Button ButtonDropSiteItem::button()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
return m_button;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
int ButtonDropSiteItem::width()
|
|
|
|
{
|
2004-12-10 17:58:37 +00:00
|
|
|
// return m_button.icon.width();
|
|
|
|
return 20;
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
int ButtonDropSiteItem::height()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-10 17:58:37 +00:00
|
|
|
// return m_button.icon.height();
|
|
|
|
return 20;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
void ButtonDropSiteItem::draw(QPainter *p, const QPalette& cg, QRect r)
|
2004-12-09 21:33:16 +00:00
|
|
|
{
|
2004-12-10 17:58:37 +00:00
|
|
|
// p->fillRect(r, cg.base() );
|
2004-12-10 18:28:28 +00:00
|
|
|
if (m_button.supported)
|
2006-04-30 09:16:13 +00:00
|
|
|
p->setPen(cg.color(QPalette::Foreground) );
|
2004-12-10 18:28:28 +00:00
|
|
|
else
|
2006-04-30 09:16:13 +00:00
|
|
|
p->setPen( cg.color(QPalette::Mid) );
|
2004-12-10 17:58:37 +00:00
|
|
|
QBitmap &i = m_button.icon;
|
|
|
|
p->drawPixmap(r.left()+(r.width()-i.width())/2, r.top()+(r.height()-i.height())/2, i);
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
ButtonDropSite::ButtonDropSite( QWidget* parent, const char* name )
|
2005-11-30 21:17:50 +00:00
|
|
|
: QFrame( parent ),
|
2004-12-09 21:33:16 +00:00
|
|
|
m_selected(0)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2005-11-30 21:17:50 +00:00
|
|
|
setObjectName( name );
|
2006-02-19 01:33:48 +00:00
|
|
|
setAcceptDrops( true );
|
2002-01-16 12:26:03 +00:00
|
|
|
setFrameShape( WinPanel );
|
|
|
|
setFrameShadow( Raised );
|
|
|
|
setMinimumHeight( 26 );
|
|
|
|
setMaximumHeight( 26 );
|
|
|
|
setMinimumWidth( 250 ); // Ensure buttons will fit
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonDropSite::~ButtonDropSite()
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
clearLeft();
|
|
|
|
clearRight();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::clearLeft()
|
|
|
|
{
|
|
|
|
while (!buttonsLeft.isEmpty() ) {
|
|
|
|
ButtonDropSiteItem *item = buttonsLeft.first();
|
|
|
|
if (removeButton(item) ) {
|
|
|
|
emit buttonRemoved(item->button().type);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::clearRight()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
while (!buttonsRight.isEmpty() ) {
|
|
|
|
ButtonDropSiteItem *item = buttonsRight.first();
|
|
|
|
if (removeButton(item) ) {
|
|
|
|
emit buttonRemoved(item->button().type);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::dragMoveEvent( QDragMoveEvent* e )
|
|
|
|
{
|
|
|
|
QPoint p = e->pos();
|
2004-12-09 22:28:55 +00:00
|
|
|
if (leftDropArea().contains(p) || rightDropArea().contains(p) || buttonAt(p) ) {
|
2004-12-09 21:33:16 +00:00
|
|
|
e->accept();
|
2004-12-09 22:28:55 +00:00
|
|
|
|
|
|
|
// 2 pixel wide drop visualizer...
|
|
|
|
QRect r = contentsRect();
|
|
|
|
int x = -1;
|
|
|
|
if (leftDropArea().contains(p) ) {
|
|
|
|
x = leftDropArea().left();
|
|
|
|
} else if (rightDropArea().contains(p) ) {
|
|
|
|
x = rightDropArea().right()+1;
|
|
|
|
} else {
|
|
|
|
ButtonDropSiteItem *item = buttonAt(p);
|
|
|
|
if (item) {
|
|
|
|
if (p.x() < item->rect.left()+item->rect.width()/2 ) {
|
|
|
|
x = item->rect.left();
|
|
|
|
} else {
|
|
|
|
x = item->rect.right()+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (x != -1) {
|
|
|
|
QRect tmpRect(x, r.y(), 2, r.height() );
|
|
|
|
if (tmpRect != m_oldDropVisualizer) {
|
|
|
|
cleanDropVisualizer();
|
|
|
|
m_oldDropVisualizer = tmpRect;
|
|
|
|
update(tmpRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2004-12-09 21:33:16 +00:00
|
|
|
e->ignore();
|
2004-12-09 22:28:55 +00:00
|
|
|
|
|
|
|
cleanDropVisualizer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonDropSite::cleanDropVisualizer()
|
|
|
|
{
|
|
|
|
if (m_oldDropVisualizer.isValid())
|
|
|
|
{
|
|
|
|
QRect rect = m_oldDropVisualizer;
|
|
|
|
m_oldDropVisualizer = QRect(); // rect is invalid
|
|
|
|
update(rect);
|
|
|
|
}
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
void ButtonDropSite::dragEnterEvent( QDragEnterEvent* e )
|
|
|
|
{
|
|
|
|
if ( ButtonDrag::canDecode( e ) )
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonDropSite::dragLeaveEvent( QDragLeaveEvent* /* e */ )
|
|
|
|
{
|
2004-12-09 22:28:55 +00:00
|
|
|
cleanDropVisualizer();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonDropSite::dropEvent( QDropEvent* e )
|
|
|
|
{
|
2004-12-09 22:28:55 +00:00
|
|
|
cleanDropVisualizer();
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
QPoint p = e->pos();
|
|
|
|
|
|
|
|
// collect information where to insert the dropped button
|
|
|
|
ButtonList *buttonList = 0;
|
|
|
|
ButtonList::iterator buttonPosition;
|
|
|
|
|
|
|
|
if (leftDropArea().contains(p) ) {
|
|
|
|
buttonList = &buttonsLeft;
|
|
|
|
buttonPosition = buttonsLeft.end();
|
|
|
|
} else if (rightDropArea().contains(p) ) {
|
|
|
|
buttonList = &buttonsRight;
|
|
|
|
buttonPosition = buttonsRight.begin();
|
|
|
|
} else {
|
|
|
|
ButtonDropSiteItem *aboveItem = buttonAt(p);
|
|
|
|
if (!aboveItem)
|
2006-05-31 16:23:36 +00:00
|
|
|
return; // invalid drop. hasn't occurred _over_ a button (or left/right dropArea), return...
|
2004-12-09 21:33:16 +00:00
|
|
|
|
|
|
|
ButtonList::iterator it;
|
|
|
|
if (!getItemIterator(aboveItem, buttonList, it) ) {
|
|
|
|
// didn't find the aboveItem. unlikely to happen since buttonAt() already seems to have found
|
|
|
|
// something valid. anyway...
|
|
|
|
return;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// got the list and the aboveItem position. now determine if the item should be inserted
|
|
|
|
// before aboveItem or after aboveItem.
|
|
|
|
QRect aboveItemRect = aboveItem->rect;
|
|
|
|
if (!aboveItemRect.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p.x() < aboveItemRect.left()+aboveItemRect.width()/2 ) {
|
|
|
|
// insert before the item
|
|
|
|
buttonPosition = it;
|
|
|
|
} else {
|
|
|
|
if (it != buttonList->end() )
|
|
|
|
buttonPosition = ++it;
|
2002-01-16 12:26:03 +00:00
|
|
|
else
|
2004-12-09 21:33:16 +00:00
|
|
|
buttonPosition = it; // already at the end(), can't increment the iterator!
|
|
|
|
}
|
|
|
|
}
|
2003-09-16 19:34:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// know where to insert the button. now see if we can use an existing item (drag within the widget = move)
|
|
|
|
// orneed to create a new one
|
|
|
|
ButtonDropSiteItem *buttonItem = 0;
|
|
|
|
if (e->source() == this && m_selected) {
|
|
|
|
ButtonList *oldList = 0;
|
|
|
|
ButtonList::iterator oldPos;
|
|
|
|
if (getItemIterator(m_selected, oldList, oldPos) ) {
|
|
|
|
if (oldPos == buttonPosition)
|
|
|
|
return; // button didn't change its position during the drag...
|
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
oldList->erase(oldPos);
|
2004-12-09 21:33:16 +00:00
|
|
|
buttonItem = m_selected;
|
|
|
|
} else {
|
|
|
|
return; // m_selected not found, return...
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// create new button from the drop object...
|
|
|
|
Button btn;
|
|
|
|
if (ButtonDrag::decode(e, btn) ) {
|
|
|
|
buttonItem = new ButtonDropSiteItem(btn);
|
|
|
|
} else {
|
|
|
|
return; // something has gone wrong while we were trying to decode the drop event
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// now the item can actually be inserted into the list! :)
|
|
|
|
(*buttonList).insert(buttonPosition, buttonItem);
|
|
|
|
emit buttonAdded(buttonItem->button().type);
|
|
|
|
emit changed();
|
|
|
|
recalcItemGeometry();
|
|
|
|
update();
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
bool ButtonDropSite::getItemIterator(ButtonDropSiteItem *item, ButtonList* &list, ButtonList::iterator &iterator)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
if (!item)
|
|
|
|
return false;
|
2003-09-16 19:34:03 +00:00
|
|
|
|
2006-04-29 14:38:17 +00:00
|
|
|
int ind = buttonsLeft.indexOf(item); // try the left list first...
|
|
|
|
if (ind < 0 ) {
|
|
|
|
ind = buttonsRight.indexOf(item); // try the right list...
|
|
|
|
if ( ind < 0 ) {
|
2004-12-09 21:33:16 +00:00
|
|
|
return false; // item hasn't been found in one of the list, return...
|
|
|
|
} else {
|
|
|
|
list = &buttonsRight;
|
2006-04-29 14:38:17 +00:00
|
|
|
iterator = buttonsRight.begin()+ind;
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list = &buttonsLeft;
|
2006-04-29 14:38:17 +00:00
|
|
|
buttonsLeft.begin()+ind;
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
QRect ButtonDropSite::leftDropArea()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// return a 10 pixel drop area...
|
|
|
|
QRect r = contentsRect();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
int leftButtonsWidth = calcButtonListWidth(buttonsLeft);
|
|
|
|
return QRect(r.left()+leftButtonsWidth, r.top(), 10, r.height() );
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
QRect ButtonDropSite::rightDropArea()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// return a 10 pixel drop area...
|
|
|
|
QRect r = contentsRect();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
int rightButtonsWidth = calcButtonListWidth(buttonsRight);
|
|
|
|
return QRect(r.right()-rightButtonsWidth-10, r.top(), 10, r.height() );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::mousePressEvent( QMouseEvent* e )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// TODO: only start the real drag after some drag distance
|
|
|
|
m_selected = buttonAt(e->pos() );
|
|
|
|
if (m_selected) {
|
|
|
|
ButtonDrag *bd = new ButtonDrag(m_selected->button(), this);
|
2006-04-12 15:13:31 +00:00
|
|
|
bd->setPixmap(bitmapPixmap(m_selected->button().icon, palette().color( QPalette::Foreground ) ) );
|
2004-12-09 21:33:16 +00:00
|
|
|
bd->dragMove();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::resizeEvent(QResizeEvent*)
|
|
|
|
{
|
|
|
|
recalcItemGeometry();
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::recalcItemGeometry()
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
QRect r = contentsRect();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// update the geometry of the items in the left button list
|
|
|
|
int offset = r.left();
|
|
|
|
for (ButtonList::const_iterator it = buttonsLeft.begin(); it != buttonsLeft.end(); ++it) {
|
|
|
|
int w = (*it)->width();
|
|
|
|
(*it)->rect = QRect(offset, r.top(), w, (*it)->height() );
|
|
|
|
offset += w;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// the right button list...
|
|
|
|
offset = r.right() - calcButtonListWidth(buttonsRight);
|
|
|
|
for (ButtonList::const_iterator it = buttonsRight.begin(); it != buttonsRight.end(); ++it) {
|
|
|
|
int w = (*it)->width();
|
|
|
|
(*it)->rect = QRect(offset, r.top(), w, (*it)->height() );
|
|
|
|
offset += w;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonDropSiteItem *ButtonDropSite::buttonAt(QPoint p) {
|
|
|
|
// try to find the item in the left button list
|
|
|
|
for (ButtonList::const_iterator it = buttonsLeft.begin(); it != buttonsLeft.end(); ++it) {
|
|
|
|
if ( (*it)->rect.contains(p) ) {
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// try to find the item in the right button list
|
|
|
|
for (ButtonList::const_iterator it = buttonsRight.begin(); it != buttonsRight.end(); ++it) {
|
|
|
|
if ( (*it)->rect.contains(p) ) {
|
|
|
|
return *it;
|
2003-09-16 19:34:03 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
bool ButtonDropSite::removeButton(ButtonDropSiteItem *item) {
|
|
|
|
if (!item)
|
|
|
|
return false;
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// try to remove the item from the left button list
|
2006-04-11 17:12:05 +00:00
|
|
|
if (buttonsLeft.removeAll(item) >= 1) {
|
2004-12-09 21:33:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
// try to remove the item from the right button list
|
2006-04-11 17:12:05 +00:00
|
|
|
if (buttonsRight.removeAll(item) >= 1) {
|
2004-12-09 21:33:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
int ButtonDropSite::calcButtonListWidth(const ButtonList& btns)
|
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
for (ButtonList::const_iterator it = btns.begin(); it != btns.end(); ++it) {
|
|
|
|
w += (*it)->width();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ButtonDropSite::removeSelectedButton()
|
|
|
|
{
|
|
|
|
bool succ = removeButton(m_selected);
|
|
|
|
if (succ) {
|
|
|
|
emit buttonRemoved(m_selected->button().type);
|
|
|
|
emit changed();
|
|
|
|
delete m_selected;
|
|
|
|
m_selected = 0;
|
|
|
|
recalcItemGeometry();
|
|
|
|
update(); // repaint...
|
2003-09-16 19:34:03 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
return succ;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
void ButtonDropSite::drawButtonList(QPainter *p, const ButtonList& btns, int offset)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
for (ButtonList::const_iterator it = btns.begin(); it != btns.end(); ++it) {
|
|
|
|
QRect itemRect = (*it)->rect;
|
|
|
|
if (itemRect.isValid() ) {
|
2006-04-30 09:16:13 +00:00
|
|
|
(*it)->draw(p, palette(), itemRect);
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
offset += (*it)->width();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonDropSite::drawContents( QPainter* p )
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
int leftoffset = calcButtonListWidth( buttonsLeft );
|
|
|
|
int rightoffset = calcButtonListWidth( buttonsRight );
|
2002-01-16 12:26:03 +00:00
|
|
|
int offset = 3;
|
|
|
|
|
|
|
|
QRect r = contentsRect();
|
|
|
|
|
|
|
|
// Shrink by 1
|
2006-02-22 10:18:39 +00:00
|
|
|
r.translate(1 + leftoffset, 1);
|
2002-01-16 12:26:03 +00:00
|
|
|
r.setWidth( r.width() - 2 - leftoffset - rightoffset );
|
|
|
|
r.setHeight( r.height() - 2 );
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
drawButtonList( p, buttonsLeft, offset );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
QColor c1( 0x0A, 0x5F, 0x89 ); // KDE 2 titlebar default colour
|
|
|
|
p->fillRect( r, c1 );
|
|
|
|
p->setPen( Qt::white );
|
2003-07-19 08:02:40 +00:00
|
|
|
p->setFont( QFont( KGlobalSettings::generalFont().family(), 12, QFont::Bold) );
|
2005-07-28 14:59:42 +00:00
|
|
|
p->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, i18n("KDE") );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
offset = geometry().width() - 3 - rightoffset;
|
2004-12-09 21:33:16 +00:00
|
|
|
drawButtonList( p, buttonsRight, offset );
|
2004-12-09 22:28:55 +00:00
|
|
|
|
|
|
|
if (m_oldDropVisualizer.isValid() )
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
p->fillRect(m_oldDropVisualizer, Qt::Dense4Pattern);
|
2004-12-09 22:28:55 +00:00
|
|
|
}
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
ButtonSourceItem::ButtonSourceItem(Q3ListView * parent, const Button& btn)
|
|
|
|
: Q3ListViewItem(parent),
|
2004-12-10 17:58:37 +00:00
|
|
|
m_button(btn),
|
|
|
|
m_dirty(true)
|
2004-12-09 21:33:16 +00:00
|
|
|
{
|
|
|
|
setButton(btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonSourceItem::~ButtonSourceItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
void ButtonSourceItem::paintCell(QPainter *p, const QPalette &cg, int column, int width, int align)
|
2004-12-09 21:33:16 +00:00
|
|
|
{
|
2004-12-10 17:58:37 +00:00
|
|
|
// we need the color group cg, so to the work here, not in setButton...
|
|
|
|
if (m_dirty) {
|
|
|
|
if (m_button.supported) {
|
2006-04-30 17:09:09 +00:00
|
|
|
setPixmap(0, bitmapPixmap(m_button.icon, cg.color( QPalette::Foreground ) ) );
|
2004-12-10 17:58:37 +00:00
|
|
|
} else {
|
2006-04-30 17:09:09 +00:00
|
|
|
setPixmap(0, bitmapPixmap(m_button.icon, cg.color( QPalette::Mid ) ) );
|
2004-12-10 17:58:37 +00:00
|
|
|
}
|
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
if (m_button.supported) {
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItem::paintCell(p,cg,column,width,align);
|
2004-12-09 21:33:16 +00:00
|
|
|
} else {
|
|
|
|
// grey out unsupported buttons
|
2006-04-30 09:16:13 +00:00
|
|
|
QPalette cg2 = cg;
|
2006-04-30 17:09:09 +00:00
|
|
|
cg2.setColor(QPalette::Text, cg.color(QPalette::Mid) );
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItem::paintCell(p,cg2,column,width,align);
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonSourceItem::setButton(const Button& btn)
|
|
|
|
{
|
|
|
|
m_button = btn;
|
2004-12-10 17:58:37 +00:00
|
|
|
m_dirty = true; // update the pixmap when in paintCell()...
|
2004-12-09 21:33:16 +00:00
|
|
|
if (btn.supported) {
|
|
|
|
setText(0, btn.name);
|
|
|
|
} else {
|
2006-04-10 11:57:13 +00:00
|
|
|
setText(0, i18n("%1 (unavailable)", btn.name) );
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button ButtonSourceItem::button() const
|
|
|
|
{
|
|
|
|
return m_button;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
|
2004-12-03 22:23:20 +00:00
|
|
|
ButtonPositionWidget::ButtonPositionWidget(QWidget *parent, const char* name)
|
2006-04-12 15:13:31 +00:00
|
|
|
: QWidget(parent),
|
2004-12-10 18:28:28 +00:00
|
|
|
m_factory(0)
|
2004-12-03 22:23:20 +00:00
|
|
|
{
|
2006-04-12 15:13:31 +00:00
|
|
|
setObjectName( name );
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(KDialog::spacingHint());
|
2004-12-09 21:33:16 +00:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
2004-12-03 22:23:20 +00:00
|
|
|
|
|
|
|
QLabel* label = new QLabel( this );
|
2004-12-09 21:33:16 +00:00
|
|
|
m_dropSite = new ButtonDropSite( this );
|
2005-07-28 14:59:42 +00:00
|
|
|
label->setWordWrap( true );
|
2004-12-03 22:23:20 +00:00
|
|
|
label->setText( i18n( "To add or remove titlebar buttons, simply <i>drag</i> items "
|
|
|
|
"between the available item list and the titlebar preview. Similarly, "
|
|
|
|
"drag items within the titlebar preview to re-position them.") );
|
2005-10-22 18:13:37 +00:00
|
|
|
m_buttonSource = new ButtonSource(this);
|
|
|
|
m_buttonSource->setObjectName("button_source");
|
2004-12-03 22:23:20 +00:00
|
|
|
|
|
|
|
layout->addWidget(label);
|
2004-12-09 21:33:16 +00:00
|
|
|
layout->addWidget(m_dropSite);
|
|
|
|
layout->addWidget(m_buttonSource);
|
|
|
|
|
|
|
|
connect( m_dropSite, SIGNAL(buttonAdded(QChar)), m_buttonSource, SLOT(hideButton(QChar)) );
|
|
|
|
connect( m_dropSite, SIGNAL(buttonRemoved(QChar)), m_buttonSource, SLOT(showButton(QChar)) );
|
2005-07-28 14:59:42 +00:00
|
|
|
connect( m_buttonSource, SIGNAL(dropped(QDropEvent*, Q3ListViewItem*)), m_dropSite, SLOT(removeSelectedButton()) );
|
2004-12-09 21:33:16 +00:00
|
|
|
|
|
|
|
connect( m_dropSite, SIGNAL(changed()), SIGNAL(changed()) );
|
|
|
|
|
|
|
|
// insert all possible buttons into the source (backwards to keep the preferred order...)
|
|
|
|
bool dummy;
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('R', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('L', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('B', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('F', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('X', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('A', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('I', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('H', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('S', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('M', dummy) );
|
|
|
|
new ButtonSourceItem(m_buttonSource, getButton('_', dummy) );
|
2004-12-03 22:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ButtonPositionWidget::~ButtonPositionWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-10 18:28:28 +00:00
|
|
|
void ButtonPositionWidget::setDecorationFactory(KDecorationFactory *factory)
|
|
|
|
{
|
|
|
|
if (!factory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_factory = factory;
|
|
|
|
|
|
|
|
// get the list of supported buttons
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityAnnounceButtons) ) {
|
|
|
|
QString supportedButtons;
|
|
|
|
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonMenu) )
|
|
|
|
supportedButtons.append('M');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonOnAllDesktops) )
|
|
|
|
supportedButtons.append('S');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonSpacer) )
|
|
|
|
supportedButtons.append('_');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonHelp) )
|
|
|
|
supportedButtons.append('H');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonMinimize) )
|
|
|
|
supportedButtons.append('I');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonMaximize) )
|
|
|
|
supportedButtons.append('A');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonClose) )
|
|
|
|
supportedButtons.append('X');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonAboveOthers) )
|
|
|
|
supportedButtons.append('F');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonBelowOthers) )
|
|
|
|
supportedButtons.append('B');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonShade) )
|
|
|
|
supportedButtons.append('L');
|
|
|
|
if (m_factory->supports(KDecorationDefines::AbilityButtonResize) )
|
|
|
|
supportedButtons.append('R');
|
|
|
|
|
|
|
|
m_supportedButtons = supportedButtons;
|
|
|
|
} else {
|
2005-04-29 09:44:40 +00:00
|
|
|
// enable only buttons available before AbilityButton* introduction
|
|
|
|
m_supportedButtons = "MSHIAX_";
|
2004-12-10 18:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update the button lists...
|
|
|
|
// 1. set status on the source items...
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItemIterator it(m_buttonSource);
|
2004-12-10 18:28:28 +00:00
|
|
|
while (it.current() ) {
|
|
|
|
ButtonSourceItem *i = dynamic_cast<ButtonSourceItem*>(it.current() );
|
|
|
|
if (i) {
|
|
|
|
Button b = i->button();
|
|
|
|
b.supported = m_supportedButtons.contains(b.type);
|
|
|
|
i->setButton(b);
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
// 2. rebuild the drop site items...
|
|
|
|
setButtonsLeft(buttonsLeft() );
|
|
|
|
setButtonsRight(buttonsRight() );
|
|
|
|
}
|
|
|
|
|
2004-12-09 21:33:16 +00:00
|
|
|
Button ButtonPositionWidget::getButton(QChar type, bool& success) {
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
if (type == 'R') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( resize_width, resize_height ), resize_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Resize"), bmp, 'R', false, m_supportedButtons.contains('R') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'L') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( shade_width, shade_height ), shade_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Shade"), bmp, 'L', false, m_supportedButtons.contains('L') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'B') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( keepbelowothers_width, keepbelowothers_height ), keepbelowothers_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Keep Below Others"), bmp, 'B', false, m_supportedButtons.contains('B') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'F') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( keepaboveothers_width, keepaboveothers_height ), keepaboveothers_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Keep Above Others"), bmp, 'F', false, m_supportedButtons.contains('F') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'X') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( close_width, close_height ), close_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2006-04-10 11:57:13 +00:00
|
|
|
return Button(i18n("Close"), bmp, 'X', false, m_supportedButtons.contains('X') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'A') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( maximize_width, maximize_height ), maximize_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Maximize"), bmp, 'A', false, m_supportedButtons.contains('A') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'I') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( minimize_width, minimize_height ), minimize_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Minimize"), bmp, 'I', false, m_supportedButtons.contains('I') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'H') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( help_width, help_height ), help_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Help"), bmp, 'H', false, m_supportedButtons.contains('H') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'S') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( onalldesktops_width, onalldesktops_height ), onalldesktops_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("On All Desktops"), bmp, 'S', false, m_supportedButtons.contains('S') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == 'M') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( menu_width, menu_height ), menu_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("Menu"), bmp, 'M', false, m_supportedButtons.contains('M') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else if (type == '_') {
|
2006-04-12 15:13:31 +00:00
|
|
|
QBitmap bmp = QBitmap::fromData(QSize( spacer_width, spacer_height ), spacer_bits);
|
2004-12-10 17:58:37 +00:00
|
|
|
bmp.setMask(bmp);
|
2004-12-10 18:28:28 +00:00
|
|
|
return Button(i18n("--- spacer ---"), bmp, '_', true, m_supportedButtons.contains('_') );
|
2004-12-09 21:33:16 +00:00
|
|
|
} else {
|
|
|
|
success = false;
|
2005-06-08 13:31:12 +00:00
|
|
|
return Button();
|
2004-12-09 21:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-03 22:23:20 +00:00
|
|
|
QString ButtonPositionWidget::buttonsLeft() const
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonList btns = m_dropSite->buttonsLeft;
|
|
|
|
QString btnString = "";
|
|
|
|
for (ButtonList::const_iterator it = btns.begin(); it != btns.end(); ++it) {
|
|
|
|
btnString.append( (*it)->button().type );
|
|
|
|
}
|
|
|
|
return btnString;
|
2004-12-03 22:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ButtonPositionWidget::buttonsRight() const
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
ButtonList btns = m_dropSite->buttonsRight;
|
|
|
|
QString btnString = "";
|
|
|
|
for (ButtonList::const_iterator it = btns.begin(); it != btns.end(); ++it) {
|
|
|
|
btnString.append( (*it)->button().type );
|
|
|
|
}
|
|
|
|
return btnString;
|
2004-12-03 22:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonPositionWidget::setButtonsLeft(const QString &buttons)
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// to keep the button lists consistent, first remove all left buttons, then add buttons again...
|
|
|
|
m_dropSite->clearLeft();
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
for (int i = 0; i < buttons.length(); ++i) {
|
2004-12-09 21:33:16 +00:00
|
|
|
bool succ = false;
|
|
|
|
Button btn = getButton(buttons[i], succ);
|
|
|
|
if (succ) {
|
|
|
|
m_dropSite->buttonsLeft.append(new ButtonDropSiteItem(btn) );
|
|
|
|
m_buttonSource->hideButton(btn.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_dropSite->recalcItemGeometry();
|
|
|
|
m_dropSite->update();
|
2004-12-03 22:23:20 +00:00
|
|
|
}
|
2005-10-03 15:54:58 +00:00
|
|
|
|
2004-12-03 22:23:20 +00:00
|
|
|
void ButtonPositionWidget::setButtonsRight(const QString &buttons)
|
|
|
|
{
|
2004-12-09 21:33:16 +00:00
|
|
|
// to keep the button lists consistent, first remove all left buttons, then add buttons again...
|
|
|
|
m_dropSite->clearRight();
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
for (int i = 0; i < buttons.length(); ++i) {
|
2004-12-09 21:33:16 +00:00
|
|
|
bool succ = false;
|
|
|
|
Button btn = getButton(buttons[i], succ);
|
|
|
|
if (succ) {
|
|
|
|
m_dropSite->buttonsRight.append(new ButtonDropSiteItem(btn) );
|
|
|
|
m_buttonSource->hideButton(btn.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_dropSite->recalcItemGeometry();
|
|
|
|
m_dropSite->update();
|
2004-12-03 22:23:20 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
#include "buttons.moc"
|
|
|
|
// vim: ts=4
|
2004-12-03 22:23:20 +00:00
|
|
|
// kate: space-indent off; tab-width 4;
|