Port Plastik to KCommonDecoration.
svn path=/trunk/kdebase/kwin/; revision=396773
This commit is contained in:
parent
37992c3cb1
commit
74dda10aaa
5 changed files with 416 additions and 872 deletions
|
@ -30,19 +30,6 @@ namespace KWinPlastik {
|
|||
|
||||
#include <qfont.h>
|
||||
|
||||
enum ButtonType {
|
||||
HelpButton=0,
|
||||
MaxButton,
|
||||
MinButton,
|
||||
CloseButton,
|
||||
MenuButton,
|
||||
OnAllDesktopsButton,
|
||||
AboveButton,
|
||||
BelowButton,
|
||||
ShadeButton,
|
||||
NumButtons
|
||||
};
|
||||
|
||||
enum ColorType {
|
||||
WindowContour=0,
|
||||
TitleGradientFrom,
|
||||
|
|
|
@ -59,31 +59,16 @@ namespace KWinPlastik
|
|||
static const uint TIMERINTERVAL = 50; // msec
|
||||
static const uint ANIMATIONSTEPS = 4;
|
||||
|
||||
PlastikButton::PlastikButton(PlastikClient *parent, const char *name,
|
||||
const QString& tip, ButtonType type,
|
||||
int size, bool toggle, int btns)
|
||||
: QButton(parent->widget(), name),
|
||||
PlastikButton::PlastikButton(ButtonType type, PlastikClient *parent, const char *name)
|
||||
: KCommonDecorationButton(type, parent, name),
|
||||
m_client(parent),
|
||||
m_lastMouse(NoButton),
|
||||
m_realizeButtons(btns),
|
||||
m_size(size),
|
||||
m_type(type),
|
||||
m_aDecoLight(QImage() ), m_iDecoLight(QImage() ),
|
||||
m_aDecoDark(QImage() ), m_iDecoDark(QImage() ),
|
||||
hover(false)
|
||||
{
|
||||
QToolTip::add( this, tip );
|
||||
setCursor(ArrowCursor);
|
||||
|
||||
setBackgroundMode(NoBackground);
|
||||
|
||||
setToggleButton(toggle);
|
||||
|
||||
if(m_size < 10) { m_size = 10; }
|
||||
|
||||
setFixedSize(m_size, m_size);
|
||||
|
||||
setDeco();
|
||||
reset();
|
||||
|
||||
animTmr = new QTimer(this);
|
||||
connect(animTmr, SIGNAL(timeout() ), this, SLOT(animate() ) );
|
||||
|
@ -94,26 +79,7 @@ PlastikButton::~PlastikButton()
|
|||
{
|
||||
}
|
||||
|
||||
QSize PlastikButton::sizeHint() const
|
||||
{
|
||||
return QSize(m_size, m_size);
|
||||
}
|
||||
|
||||
void PlastikButton::setSize(int s)
|
||||
{
|
||||
m_size = s;
|
||||
if(m_size < 10) { m_size = 10; }
|
||||
setFixedSize(m_size, m_size);
|
||||
setDeco();
|
||||
}
|
||||
|
||||
void PlastikButton::setOn(bool on)
|
||||
{
|
||||
QButton::setOn(on);
|
||||
setDeco();
|
||||
}
|
||||
|
||||
void PlastikButton::setDeco()
|
||||
void PlastikButton::reset()
|
||||
{
|
||||
QColor aDecoFgDark = alphaBlendColors(PlastikHandler::getColor(TitleGradientTo, true),
|
||||
Qt::black, 50);
|
||||
|
@ -136,7 +102,7 @@ void PlastikButton::setDeco()
|
|||
reduceH = 4;
|
||||
|
||||
QImage img;
|
||||
switch (m_type) {
|
||||
switch (type() ) {
|
||||
case CloseButton:
|
||||
img = QImage(close_xpm);
|
||||
break;
|
||||
|
@ -194,11 +160,6 @@ void PlastikButton::setDeco()
|
|||
this->update();
|
||||
}
|
||||
|
||||
void PlastikButton::setTipText(const QString &tip) {
|
||||
QToolTip::remove(this );
|
||||
QToolTip::add(this, tip );
|
||||
}
|
||||
|
||||
void PlastikButton::animate()
|
||||
{
|
||||
animTmr->stop();
|
||||
|
@ -244,31 +205,8 @@ void PlastikButton::leaveEvent(QEvent *e)
|
|||
// repaint(false);
|
||||
}
|
||||
|
||||
void PlastikButton::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
m_lastMouse = e->button();
|
||||
// pass on event after changing button to LeftButton
|
||||
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
||||
(e->button()&m_realizeButtons)?LeftButton:NoButton, e->state());
|
||||
|
||||
QButton::mousePressEvent(&me);
|
||||
}
|
||||
|
||||
void PlastikButton::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
m_lastMouse = e->button();
|
||||
// pass on event after changing button to LeftButton
|
||||
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
||||
(e->button()&m_realizeButtons)?LeftButton:NoButton, e->state());
|
||||
|
||||
QButton::mouseReleaseEvent(&me);
|
||||
}
|
||||
|
||||
void PlastikButton::drawButton(QPainter *painter)
|
||||
{
|
||||
if (!PlastikHandler::initialized())
|
||||
return;
|
||||
|
||||
QRect r(0,0,width(),height());
|
||||
|
||||
bool active = m_client->isActive();
|
||||
|
@ -276,7 +214,7 @@ void PlastikButton::drawButton(QPainter *painter)
|
|||
KPixmap tempKPixmap;
|
||||
|
||||
QColor highlightColor;
|
||||
if(m_type == CloseButton) {
|
||||
if(type() == CloseButton) {
|
||||
highlightColor = QColor(255,64,0);
|
||||
} else {
|
||||
highlightColor = Qt::white;
|
||||
|
@ -312,7 +250,7 @@ void PlastikButton::drawButton(QPainter *painter)
|
|||
// fill with the titlebar background
|
||||
bP.drawTiledPixmap(0, 0, width(), width(), backgroundTile);
|
||||
|
||||
if (m_type != MenuButton || hover || animProgress != 0) {
|
||||
if (type() != MenuButton || hover || animProgress != 0) {
|
||||
// contour
|
||||
bP.setPen(contourTop);
|
||||
bP.drawLine(r.x()+2, r.y(), r.right()-2, r.y() );
|
||||
|
@ -358,7 +296,7 @@ void PlastikButton::drawButton(QPainter *painter)
|
|||
bP.drawTiledPixmap(r.x()+1, r.y()+2, r.width()-2, r.height()-4, tempKPixmap);
|
||||
}
|
||||
|
||||
if (m_type == MenuButton)
|
||||
if (type() == MenuButton)
|
||||
{
|
||||
QPixmap menuIcon(m_client->icon().pixmap( QIconSet::Small, QIconSet::Normal));
|
||||
if (width() < menuIcon.width() || height() < menuIcon.height() ) {
|
||||
|
|
|
@ -27,27 +27,23 @@
|
|||
#include <qimage.h>
|
||||
#include "plastik.h"
|
||||
|
||||
#include <kcommondecoration.h>
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace KWinPlastik {
|
||||
|
||||
class PlastikClient;
|
||||
|
||||
class PlastikButton : public QButton
|
||||
class PlastikButton : public KCommonDecorationButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlastikButton(PlastikClient *parent, const char *name, const QString &tip, ButtonType type, int size, bool toggle = false, int btns = LeftButton);
|
||||
PlastikButton(ButtonType type, PlastikClient *parent, const char *name);
|
||||
~PlastikButton();
|
||||
|
||||
QSize sizeHint() const; ///< Return size hint.
|
||||
ButtonState lastMousePress() const { return m_lastMouse; }
|
||||
void reset() { repaint(false); }
|
||||
void reset();
|
||||
PlastikClient * client() { return m_client; }
|
||||
virtual void setOn(bool on);
|
||||
void setDeco();
|
||||
void setTipText(const QString &tip);
|
||||
void setSize(const int s);
|
||||
|
||||
protected slots:
|
||||
void animate();
|
||||
|
@ -55,18 +51,10 @@ protected slots:
|
|||
private:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void drawButton(QPainter *painter);
|
||||
|
||||
private:
|
||||
PlastikClient *m_client;
|
||||
ButtonState m_lastMouse;
|
||||
int m_realizeButtons;
|
||||
|
||||
int m_size;
|
||||
|
||||
ButtonType m_type;
|
||||
QImage m_aDecoLight,m_iDecoLight,m_aDecoDark,m_iDecoDark;
|
||||
bool hover;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,74 +23,41 @@
|
|||
#ifndef KNIFTYCLIENT_H
|
||||
#define KNIFTYCLIENT_H
|
||||
|
||||
#include <kdecoration.h>
|
||||
#include "plastik.h"
|
||||
#include <kcommondecoration.h>
|
||||
|
||||
class QSpacerItem;
|
||||
class QVBoxLayout;
|
||||
class QBoxLayout;
|
||||
#include "plastik.h"
|
||||
|
||||
namespace KWinPlastik {
|
||||
|
||||
class PlastikButton;
|
||||
|
||||
class PlastikClient : public KDecoration
|
||||
class PlastikClient : public KCommonDecoration
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory);
|
||||
~PlastikClient();
|
||||
|
||||
virtual void init();
|
||||
virtual QString visibleName() const;
|
||||
virtual QString defaultButtonsLeft() const;
|
||||
virtual QString defaultButtonsRight() const;
|
||||
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
|
||||
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const;
|
||||
virtual QRegion cornerShape(WindowCorner corner);
|
||||
virtual KCommonDecorationButton *createButton(ButtonType type);
|
||||
|
||||
virtual void borders( int& left, int& right, int& top, int& bottom ) const;
|
||||
virtual void resize(const QSize&);
|
||||
virtual QSize minimumSize() const;
|
||||
virtual void show();
|
||||
virtual bool eventFilter( QObject* o, QEvent* e );
|
||||
virtual void init();
|
||||
virtual void reset( unsigned long changed );
|
||||
|
||||
virtual void paintEvent(QPaintEvent *e);
|
||||
virtual void updateCaption();
|
||||
|
||||
QPixmap getTitleBarTile(bool active) const
|
||||
{
|
||||
return active ? *aTitleBarTile : *iTitleBarTile;
|
||||
}
|
||||
protected:
|
||||
virtual void resizeEvent();
|
||||
virtual void paintEvent(QPaintEvent *e);
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
|
||||
virtual void maximizeChange();
|
||||
virtual void desktopChange();
|
||||
virtual void shadeChange();
|
||||
virtual void doShape();
|
||||
|
||||
virtual void reset( unsigned long changed );
|
||||
|
||||
virtual void captionChange();
|
||||
virtual void iconChange();
|
||||
virtual void activeChange();
|
||||
virtual Position mousePosition(const QPoint &point) const;
|
||||
|
||||
private slots:
|
||||
void keepAboveChange(bool above);
|
||||
void keepBelowChange(bool below);
|
||||
void slotMaximize();
|
||||
void slotShade();
|
||||
void slotKeepAbove();
|
||||
void slotKeepBelow();
|
||||
void menuButtonPressed();
|
||||
void menuButtonReleased();
|
||||
bool isTool();
|
||||
private:
|
||||
void _resetLayout();
|
||||
void addButtons(QBoxLayout* layout, const QString& buttons, int buttonSize = 18);
|
||||
|
||||
QVBoxLayout *mainLayout_;
|
||||
QSpacerItem *topSpacer_,
|
||||
*titleSpacer_,
|
||||
*leftTitleSpacer_, *rightTitleSpacer_,
|
||||
*decoSpacer_,
|
||||
*leftSpacer_, *rightSpacer_,
|
||||
*bottomSpacer_;
|
||||
QRect captionRect() const;
|
||||
|
||||
QPixmap *aCaptionBuffer, *iCaptionBuffer;
|
||||
void update_captionBuffer();
|
||||
|
@ -100,14 +67,11 @@ private:
|
|||
void create_pixmaps();
|
||||
void delete_pixmaps();
|
||||
|
||||
PlastikButton *m_button[NumButtons];
|
||||
|
||||
QRect m_captionRect;
|
||||
QString oldCaption;
|
||||
bool captionBufferDirty;
|
||||
|
||||
bool closing;
|
||||
|
||||
// settings...
|
||||
int s_titleHeight;
|
||||
QFont s_titleFont;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue