Back to index

kdeartwork  4.3.2
Public Member Functions | Protected Slots | Protected Member Functions | Private Attributes
CDE::CdeClient Class Reference

#include <cdeclient.h>

Collaboration diagram for CDE::CdeClient:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CdeClient (KDecorationBridge *b, KDecorationFactory *f)
 ~CdeClient ()
void init ()

Protected Slots

void menuButtonPressed ()
void menuButtonReleased ()
void maximizeButtonClicked ()

Protected Member Functions

bool eventFilter (QObject *o, QEvent *e)
void resizeEvent (QResizeEvent *)
void paintEvent (QPaintEvent *)
void showEvent (QShowEvent *)
void addClientButtons (const QString &)
void mouseDoubleClickEvent (QMouseEvent *)
void captionChange ()
void desktopChange ()
void activeChange ()
void shadeChange ()
void iconChange ()
QSize minimumSize () const
void resize (const QSize &size)
void borders (int &left, int &right, int &top, int &bottom) const
void mousePressEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void maximizeChange ()
Position mousePosition (const QPoint &p) const

Private Attributes

CdeButtonbutton [BtnCount]
QVBoxLayout * mainLayout
QBoxLayout * titleLayout
QSpacerItem * titlebar
bool titlebarPressed
bool closing

Detailed Description

Definition at line 68 of file cdeclient.h.


Constructor & Destructor Documentation

CDE::CdeClient::CdeClient ( KDecorationBridge *  b,
KDecorationFactory *  f 
)

Definition at line 272 of file cdeclient.cpp.

    : KDecoration(b, f)
{
}

Definition at line 73 of file cdeclient.h.

{};

Member Function Documentation

void CDE::CdeClient::activeChange ( ) [protected]

Definition at line 397 of file cdeclient.cpp.

{
    for ( int i=0; i < BtnCount; i++ )
       if ( button[i] ) button[i]->reset();

    widget()->repaint(false);
}

Here is the call graph for this function:

void CDE::CdeClient::addClientButtons ( const QString &  s) [protected]

Definition at line 327 of file cdeclient.cpp.

{
    if ( s.length() > 0 )
        for ( unsigned int i = 0; i < s.length(); i++ )
        {
            switch( s[i].latin1() )
            {
                // Menu button
                case 'M':
                    if ( ! button[BtnMenu] )
                    {
                        button[BtnMenu] = new CdeButton( this, "menu", BtnMenu, i18n("Menu"), Qt::LeftButton|Qt::RightButton );
                        connect( button[BtnMenu], SIGNAL(pressed()), SLOT(menuButtonPressed()) );
                        connect( button[BtnMenu], SIGNAL(released()), SLOT(menuButtonReleased()) );
                        titleLayout->addWidget( button[BtnMenu] );
                    }
                    break;

                //Help button
                case 'H':
                    if ( providesContextHelp() && (! button[BtnHelp] ) )
                    {
                        button[BtnHelp] = new CdeButton( this, "help", BtnHelp, i18n("Help") );
                        connect(button[BtnHelp],
                            SIGNAL(clicked()), SLOT(showContextHelp()));
                        titleLayout->addWidget( button[BtnHelp] );
                    }
                    break;

              //Minimize button
                case 'I':
                    if ( (! button[BtnIconify] ) && isMinimizable() )
                    {
                        button[BtnIconify] = new CdeButton( this, "iconify", BtnIconify, i18n("Minimize") );
                        connect(button[BtnIconify],
                            SIGNAL(clicked()), SLOT(minimize()));
                        titleLayout->addWidget( button[BtnIconify] );
                    }
                    break;

                // Maximize button
                case 'A':
                    if ( (! button[BtnMax] ) && isMaximizable() )
                    {
                        button[BtnMax] = new CdeButton(this, "maximize", BtnMax, i18n("Maximize"), Qt::LeftButton|Qt::MidButton|Qt::RightButton);
                        connect(button[BtnMax], SIGNAL(clicked()),
                            SLOT(maximizeButtonClicked()));
                        titleLayout->addWidget( button[BtnMax] );
                    }
                    break;

                // Close button
                case 'X':
                    if ( !button[BtnClose] && isCloseable())
                    {
                        button[BtnClose] = new CdeButton(this, "close", BtnClose, i18n("Close"));
                        connect( button[BtnClose], SIGNAL( clicked()), SLOT(closeWindow()) );
                        titleLayout->addWidget( button[BtnClose] );
                    }
              // Add onAlldesktops button and spacers
            }
        }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void CDE::CdeClient::borders ( int &  left,
int &  right,
int &  top,
int &  bottom 
) const [protected]

Definition at line 741 of file cdeclient.cpp.

{
    left = right = bottom = s_frameWidth + 1;
    top = s_buttonSize + s_frameWidth + 1;
}
void CDE::CdeClient::captionChange ( ) [protected]

Definition at line 392 of file cdeclient.cpp.

{
    widget()->repaint(titlebar->geometry(), false);
}
void CDE::CdeClient::desktopChange ( ) [protected]

Definition at line 428 of file cdeclient.cpp.

{
    // Nothing to do yet
}
bool CDE::CdeClient::eventFilter ( QObject *  o,
QEvent *  e 
) [protected]

Definition at line 756 of file cdeclient.cpp.

{
    if (o != widget())
       return false;
    switch (e->type()) {
    case QEvent::Resize:
       resizeEvent(static_cast< QResizeEvent* >(e));
       return true;
    case QEvent::Paint:
       paintEvent(static_cast< QPaintEvent* >(e));
       return true;
    case QEvent::MouseButtonDblClick:
       mouseDoubleClickEvent(static_cast< QMouseEvent* >(e));
       return true;
    case QEvent::MouseButtonPress:
       processMousePressEvent(static_cast< QMouseEvent* >(e));
       return true;
    case QEvent::Show:
       showEvent(static_cast< QShowEvent* >(e));
       return true;
    default:
       break;
    }
    return false;
}

Here is the call graph for this function:

void CDE::CdeClient::iconChange ( ) [protected]

Definition at line 415 of file cdeclient.cpp.

{
}

Definition at line 277 of file cdeclient.cpp.

{
    createMainWidget(WStaticContents | WResizeNoErase | WRepaintNoErase);
    widget()->installEventFilter(this);

    widget()->setBackgroundMode(NoBackground);

    mainLayout = new QVBoxLayout(widget());
    QBoxLayout* windowLayout = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0);
    titleLayout = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0);

    // TODO Check if this stuff can be simplified.
    // Border sizes are from a fixed set now.
    if ( s_frameWidth > 1 )
    {
       // the style normally draws a black frame around the window, so we
       // need 1 line of space for that in addition to the normal window frame
       mainLayout->setMargin( s_frameWidth+1 );
    }
    else
    {
       // but if the frame is set to just 1 pixel we just draw the black frame
       // instead of the normal window frame, so no extra space is needed. if
       // it is 0 we don't draw anything.
       mainLayout->setMargin( s_frameWidth );
    }

    mainLayout->addLayout( titleLayout );
    mainLayout->addLayout( windowLayout, 1 );

    if (isPreview())
        windowLayout->addWidget(new QLabel(i18n(
                     "<center><b>CDE preview</b></center>"), widget()), 1);
    else
       windowLayout->addItem( new QSpacerItem( 0, 0 ));

    for ( int i=0; i < BtnCount; i++ )
        button[i] = NULL;

    addClientButtons( options()->titleButtonsLeft() );

    titlebar = new QSpacerItem( 10, 16, QSizePolicy::Expanding, QSizePolicy::Minimum );
    titleLayout->addItem( titlebar );

    addClientButtons( options()->titleButtonsRight() );

    titlebarPressed = false;
    closing = false;
}

Here is the call graph for this function:

void CDE::CdeClient::maximizeButtonClicked ( ) [protected, slot]

Definition at line 444 of file cdeclient.cpp.

{
    if (button[BtnMax]) {
       maximize(button[BtnMax]->lastButton());
    }
}

Here is the caller graph for this function:

void CDE::CdeClient::maximizeChange ( ) [protected]

Definition at line 405 of file cdeclient.cpp.

{
    if ( button[BtnMax] ) {
       bool m = maximizeMode() == MaximizeFull;
       QToolTip::remove(button[BtnMax]);
       button[BtnMax]->setToolTip( m ? i18n("Restore") : i18n("Maximize"));
       button[BtnMax]->repaint();
    }
}
void CDE::CdeClient::menuButtonPressed ( ) [protected, slot]

Definition at line 451 of file cdeclient.cpp.

{
    static QTime* t = NULL;
    static CdeClient* lastClient = NULL;
    if( t == NULL )
       t = new QTime;
    bool dbl = ( lastClient == this && t->elapsed() <= QApplication::doubleClickInterval());
    lastClient = this;
    t->start();
    if( !dbl )
    {
       QRect menuRect = button[BtnMenu]->rect();
        QPoint menuTop = button[BtnMenu]->mapToGlobal(menuRect.topLeft());
        QPoint menuBottom = 
           button[BtnMenu]->mapToGlobal(menuRect.bottomRight());
        KDecorationFactory* f = factory();
        showWindowMenu(QRect(menuTop, menuBottom));
        if( !f->exists( this )) // 'this' was deleted
            return;
       button[BtnMenu]->setDown(false);
    }
    else
       closing = true;
}

Here is the caller graph for this function:

void CDE::CdeClient::menuButtonReleased ( ) [protected, slot]

Definition at line 476 of file cdeclient.cpp.

{
    if( closing )
        closeWindow();
}

Here is the caller graph for this function:

QSize CDE::CdeClient::minimumSize ( ) const [protected]

Definition at line 433 of file cdeclient.cpp.

{
    return QSize(2 * (s_buttonSize + s_frameWidth),
                2 * s_frameWidth + s_buttonSize);
}
void CDE::CdeClient::mouseDoubleClickEvent ( QMouseEvent *  e) [protected]

Definition at line 723 of file cdeclient.cpp.

{
    if ( e->button() == Qt::LeftButton && titlebar->geometry().contains( e->pos() ) )
       titlebarDblClickOperation();
}

Here is the caller graph for this function:

KDecoration::Position CDE::CdeClient::mousePosition ( const QPoint &  p) const [protected]

Definition at line 691 of file cdeclient.cpp.

{
    const int range = s_frameWidth + s_buttonSize;
    const int border = s_frameWidth + 1;

    Position m = PositionCenter;

    if ((p.x() > border && p.x() < width() - border)
         && (p.y() > border && p.y() < height() - border))
        return PositionCenter;

    if (p.y() < range && p.x() <= range)
        m = PositionTopLeft;
    else if (p.y() >= height() - range && p.x() >= width() - range)
        m = PositionBottomRight;
    else if (p.y() >= height()-range && p.x() <= range)
        m = PositionBottomLeft;
    else if (p.y() < range && p.x() >= width() - range)
        m = PositionTopRight;
    else if (p.y() < border)
        m = PositionTop;
    else if (p.y() >= height() - border)
        m = PositionBottom;
    else if (p.x() <= border)
        m = PositionLeft;
    else if (p.x() >= width() - border)
        m = PositionRight;
    else
        m = PositionCenter;
    return m;
}
void CDE::CdeClient::mousePressEvent ( QMouseEvent *  e) [protected]

Definition at line 729 of file cdeclient.cpp.

{
    if ( e->button() == Qt::LeftButton && titlebar->geometry().contains( e->pos() ) )
    {
       if ( titlebarButtonMode )
       {
           titlebarPressed = true;
           widget()->repaint(titlebar->geometry(), false);
       }
    }
}
void CDE::CdeClient::mouseReleaseEvent ( QMouseEvent *  e) [protected]

Definition at line 747 of file cdeclient.cpp.

{
    if ( e->button() == Qt::LeftButton && titlebarPressed )
    {
       titlebarPressed = false;
       widget()->repaint(titlebar->geometry(), false);
    }
}
void CDE::CdeClient::paintEvent ( QPaintEvent *  ) [protected]

Definition at line 512 of file cdeclient.cpp.

{
    QPainter p(widget());

    QColorGroup colorGroup;

    if ( coloredFrame )
       colorGroup = options()->colorGroup( KDecoration::ColorTitleBar, isActive() );
    else
       colorGroup = options()->colorGroup( KDecoration::ColorFrame, isActive() );

    fixColorGroup( colorGroup );

    QRect trect = titlebar->geometry();
    QRect mrect = widget()->rect();

    if ( s_frameWidth > 0 )
    {
       // draw black frame:
       p.setPen( Qt::black );
       p.drawRect( mrect );
    }

    p.setPen( Qt::NoPen );
    p.setBrush( colorGroup.background() );


    if ( s_frameWidth > 1 )
    {
       bool shaded = isShade();
       int longSide = s_frameWidth + s_buttonSize;

       // draw frame-background:
       p.drawRect( 1, 1,
              mrect.width() - 2, s_frameWidth );
       p.drawRect( 1, mrect.height() - s_frameWidth - 1,
              mrect.width() - 2, s_frameWidth );
       p.drawRect( 1, s_frameWidth + 1,
              s_frameWidth, mrect.height() - 2*s_frameWidth - 2 );
       p.drawRect( mrect.width() - s_frameWidth - 1, s_frameWidth + 1,
              s_frameWidth, mrect.height() - 2*s_frameWidth - 2 );

       if ( ! shaded )
       {
           // draw left  and right frames:
           qDrawShadePanel( &p, 1, longSide + 1,
              s_frameWidth, mrect.height() - 2 * (longSide + 1),
              colorGroup );

           qDrawShadePanel( &p, mrect.width() - s_frameWidth - 1, longSide + 1,
              s_frameWidth, mrect.height() - 2 * (longSide + 1),
              colorGroup );
       }

       // draw top and bottom frames:
       qDrawShadePanel( &p, longSide + 1, 1,
           mrect.width() - 2 * (longSide + 1), s_frameWidth,
           colorGroup );

       qDrawShadePanel( &p, longSide + 1, mrect.height() - s_frameWidth - 1,
           mrect.width() - 2 * (longSide + 1), s_frameWidth,
           colorGroup );

       // draw light corner parts:
       p.setPen( colorGroup.light() );

       // tl corner:
       p.drawLine( 1, 1, longSide - 1, 1 );
       p.drawLine( 1, 1, 1, longSide - 1 );

       // tr corner:
       p.drawLine( mrect.width() - 3, 1, mrect.width() - longSide - 1, 1 );
       p.drawLine( mrect.width() - longSide - 1, 1,
           mrect.width() - longSide - 1, s_frameWidth - 1 );
       p.drawLine( mrect.width() - s_frameWidth - 1, s_frameWidth,
           mrect.width() - s_frameWidth - 1, longSide - 1 );

       // br corner:
       if ( !shaded )
       {
           p.drawLine( mrect.width() - 3, mrect.height() - longSide - 1,
              mrect.width() - s_frameWidth - 1, mrect.height() - longSide - 1 );
       }
       p.drawLine( mrect.width() - s_frameWidth - 1, mrect.height() - longSide,
           mrect.width() - s_frameWidth - 1, mrect.height() - s_frameWidth - 1 );
       p.drawLine( mrect.width() - s_frameWidth - 2, mrect.height() - s_frameWidth - 1,
           mrect.width() - longSide - 1, mrect.height() - s_frameWidth - 1 );
       p.drawLine( mrect.width() - longSide - 1, mrect.height() - s_frameWidth,
           mrect.width() - longSide - 1, mrect.height() - 2 );

       // bl corner:
       if ( !shaded )
       {
           p.drawLine( s_frameWidth-1, mrect.height() - longSide - 1,
              2, mrect.height() - longSide - 1 );
       }
       p.drawLine( 1, mrect.height() - longSide - 1,
           1, mrect.height() - 3 );
       p.drawLine( longSide - 1, mrect.height() - s_frameWidth - 1,
           s_frameWidth + 1, mrect.height() - s_frameWidth - 1 );

       // draw dark corner parts:
       p.setPen( colorGroup.dark() );

       // tl corner:
       if ( !shaded )
           p.drawLine( 1, longSide, s_frameWidth, longSide );
       p.drawLine( s_frameWidth, longSide - 1, s_frameWidth, s_frameWidth );
       p.drawLine( s_frameWidth + 1, s_frameWidth, longSide, s_frameWidth );
       p.drawLine( s_frameWidth + s_buttonSize, s_frameWidth, longSide, 1 );

       // tr corner:
       p.drawLine( mrect.width() - longSide - 1, s_frameWidth,
           mrect.width() - s_frameWidth - 2, s_frameWidth );
       if ( !shaded )
       {
           p.drawLine( mrect.width() - s_frameWidth - 1, longSide,
              mrect.width() - 2, longSide );
       }
       p.drawLine( mrect.width() - 2, longSide, mrect.width() - 2, 1 );

       // br corner:
       p.drawLine( mrect.width() - longSide - 1, mrect.height() - 2,
           mrect.width() - 3, mrect.height() - 2 );
       p.drawLine( mrect.width() - 2, mrect.height() - 2,
           mrect.width() - 2, mrect.height() - longSide - 2 );

       // bl corner:
       p.drawLine( 1, mrect.height() - 2,
              longSide, mrect.height() - 2 );
       p.drawLine( s_frameWidth + s_buttonSize, mrect.height() - 3,
              longSide, mrect.height() - s_frameWidth - 1 );
       p.drawLine( s_frameWidth, mrect.height() - s_frameWidth - 1,
              s_frameWidth, mrect.height() - longSide - 1 );
    }


    p.setPen( Qt::NoPen );

    if ( !coloredFrame )
    {
       colorGroup = options()->colorGroup( KDecoration::ColorTitleBar, isActive() );
       fixColorGroup( colorGroup );
       p.setBrush( colorGroup.background() );
    }

    // draw titlebar:
    p.drawRect( trect );
    qDrawShadePanel( &p, trect, colorGroup, titlebarPressed );

    // draw caption:
    if ( titlebarPressed ) // move the caption right and down if the titlebar is pressed
       trect.moveBy( 1,1 ); // Note: the real Mwm doesn't actually do this

    p.setFont( options()->font( true ) );
    p.setPen( options()->color( KDecoration::ColorFont, isActive() ) );
    if ( p.fontMetrics().width( caption() ) > trect.width() - 6 )
    {
       // left align the text if it is too wide to fit in the titlebar
       p.drawText( trect.x() + 3, trect.y(),
           trect.width() - 6, trect.height(),
           AlignLeft | AlignVCenter, caption() );
    }
    else
    {
       // otherwise we'll draw it according to the user settings
       p.drawText( trect.x() + 3, trect.y(),
           trect.width() - 6, trect.height(),
           textAlignment | AlignVCenter, caption() );
    }

    // Draw a line behind the wrapped window to prevent having
    // unpainted areas when we're shaded.
    p.setPen( colorGroup.dark() );
    p.drawLine(s_frameWidth + 1, mrect.height() - s_frameWidth - 2,
               mrect.width() - s_frameWidth - 2, mrect.height() - s_frameWidth - 2);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void CDE::CdeClient::resize ( const QSize &  size) [protected]

Definition at line 439 of file cdeclient.cpp.

{
    widget()->resize(s);
}
void CDE::CdeClient::resizeEvent ( QResizeEvent *  e) [protected]

Definition at line 482 of file cdeclient.cpp.

{
    if (widget()->isVisibleToTLW()) {
        widget()->update();
        int dx = 0;
        int dy = 0;

           if ( e->oldSize().width() != width() )
              dx = 32 + qAbs( e->oldSize().width() -  width() );

           if ( e->oldSize().height() != height() )
              dy = 8 + qAbs( e->oldSize().height() -  height() );

           if ( dy )
              widget()->update( 0, height() - dy + 1, width(), dy );

        if ( dx )
        {
           widget()->update( width() - dx + 1, 0, dx, height() );
           widget()->update( QRect( QPoint(4,4),
           titlebar->geometry().bottomLeft() - QPoint(1,0) ) );
           widget()->update(QRect(titlebar->geometry().topRight(),
                     QPoint(width() - 4, titlebar->geometry().bottom())));

           // Titlebar needs no paint event
           QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), false ) );
       }
    }
}

Here is the caller graph for this function:

void CDE::CdeClient::shadeChange ( ) [protected]

Definition at line 419 of file cdeclient.cpp.

{
}
void CDE::CdeClient::showEvent ( QShowEvent *  ) [protected]

Definition at line 423 of file cdeclient.cpp.

{
    widget()->repaint();
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 103 of file cdeclient.h.

bool CDE::CdeClient::closing [private]

Definition at line 108 of file cdeclient.h.

QVBoxLayout* CDE::CdeClient::mainLayout [private]

Definition at line 104 of file cdeclient.h.

QSpacerItem* CDE::CdeClient::titlebar [private]

Definition at line 106 of file cdeclient.h.

Definition at line 107 of file cdeclient.h.

QBoxLayout* CDE::CdeClient::titleLayout [private]

Definition at line 105 of file cdeclient.h.


The documentation for this class was generated from the following files: