KWinLibraries
kdecoration.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kdecoration.h"
00026 #include "kdecoration_p.h"
00027
00028 #include <kdebug.h>
00029 #include <QApplication>
00030 #include <kglobal.h>
00031 #include <assert.h>
00032 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00033 #include <X11/Xlib.h>
00034 #include <fixx11h.h>
00035 #include <QX11Info>
00036 #endif
00037
00038 #include "kdecorationfactory.h"
00039 #include "kdecorationbridge.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 KDecorationOptions* KDecoration::options_;
00059
00060 KDecoration::KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory )
00061 : bridge_( bridge ),
00062 w_( NULL ),
00063 factory_( factory )
00064 {
00065 factory->addDecoration( this );
00066 }
00067
00068 KDecoration::~KDecoration()
00069 {
00070 factory()->removeDecoration( this );
00071 delete w_;
00072 }
00073
00074 const KDecorationOptions* KDecoration::options()
00075 {
00076 return options_;
00077 }
00078
00079 void KDecoration::createMainWidget( Qt::WFlags flags )
00080 {
00081
00082 QWidget *w = new QWidget( initialParentWidget(), initialWFlags() | flags );
00083 w->setObjectName("decoration widget");
00084 w->setAttribute( Qt::WA_PaintOnScreen );
00085 w->setAttribute( Qt::WA_AlwaysShowToolTips );
00086 setMainWidget(w);
00087 }
00088
00089 void KDecoration::setMainWidget( QWidget* w )
00090 {
00091 assert( w_ == NULL );
00092 w_ = w;
00093 w->setMouseTracking( true );
00094 widget()->resize( geometry().size());
00095 }
00096
00097 QWidget* KDecoration::initialParentWidget() const
00098 {
00099 return bridge_->initialParentWidget();
00100 }
00101
00102 Qt::WFlags KDecoration::initialWFlags() const
00103 {
00104 return bridge_->initialWFlags();
00105 }
00106
00107 bool KDecoration::isActive() const
00108 {
00109 return bridge_->isActive();
00110 }
00111
00112 bool KDecoration::isCloseable() const
00113 {
00114 return bridge_->isCloseable();
00115 }
00116
00117 bool KDecoration::isMaximizable() const
00118 {
00119 return bridge_->isMaximizable();
00120 }
00121
00122 KDecoration::MaximizeMode KDecoration::maximizeMode() const
00123 {
00124 return bridge_->maximizeMode();
00125 }
00126
00127 bool KDecoration::isMinimizable() const
00128 {
00129 return bridge_->isMinimizable();
00130 }
00131
00132 bool KDecoration::providesContextHelp() const
00133 {
00134 return bridge_->providesContextHelp();
00135 }
00136
00137 int KDecoration::desktop() const
00138 {
00139 return bridge_->desktop();
00140 }
00141
00142 bool KDecoration::isModal() const
00143 {
00144 return bridge_->isModal();
00145 }
00146
00147 bool KDecoration::isShadeable() const
00148 {
00149 return bridge_->isShadeable();
00150 }
00151
00152 bool KDecoration::isShade() const
00153 {
00154 return bridge_->isShade();
00155 }
00156
00157 bool KDecoration::isSetShade() const
00158 {
00159 return bridge_->isSetShade();
00160 }
00161
00162 bool KDecoration::keepAbove() const
00163 {
00164 return bridge_->keepAbove();
00165 }
00166
00167 bool KDecoration::keepBelow() const
00168 {
00169 return bridge_->keepBelow();
00170 }
00171
00172 bool KDecoration::isMovable() const
00173 {
00174 return bridge_->isMovable();
00175 }
00176
00177 bool KDecoration::isResizable() const
00178 {
00179 return bridge_->isResizable();
00180 }
00181
00182 NET::WindowType KDecoration::windowType( unsigned long supported_types ) const
00183 {
00184 return bridge_->windowType( supported_types );
00185 }
00186
00187 QIcon KDecoration::icon() const
00188 {
00189 return bridge_->icon();
00190 }
00191
00192 QString KDecoration::caption() const
00193 {
00194 return bridge_->caption();
00195 }
00196
00197 void KDecoration::processMousePressEvent( QMouseEvent* e )
00198 {
00199 return bridge_->processMousePressEvent( e );
00200 }
00201
00202 void KDecoration::showWindowMenu( const QRect &pos )
00203 {
00204 bridge_->showWindowMenu( pos );
00205 }
00206
00207 void KDecoration::showWindowMenu( QPoint pos )
00208 {
00209 bridge_->showWindowMenu( pos );
00210 }
00211
00212 void KDecoration::performWindowOperation( WindowOperation op )
00213 {
00214 bridge_->performWindowOperation( op );
00215 }
00216
00217 void KDecoration::setMask( const QRegion& reg, int mode )
00218 {
00219 bridge_->setMask( reg, mode );
00220 }
00221
00222 void KDecoration::clearMask()
00223 {
00224 bridge_->setMask( QRegion(), 0 );
00225 }
00226
00227 bool KDecoration::isPreview() const
00228 {
00229 return bridge_->isPreview();
00230 }
00231
00232 QRect KDecoration::geometry() const
00233 {
00234 return bridge_->geometry();
00235 }
00236
00237 QRect KDecoration::iconGeometry() const
00238 {
00239 return bridge_->iconGeometry();
00240 }
00241
00242 QRegion KDecoration::unobscuredRegion( const QRegion& r ) const
00243 {
00244 return bridge_->unobscuredRegion( r );
00245 }
00246
00247 WId KDecoration::windowId() const
00248 {
00249 return bridge_->windowId();
00250 }
00251
00252 void KDecoration::closeWindow()
00253 {
00254 bridge_->closeWindow();
00255 }
00256
00257 void KDecoration::maximize( Qt::MouseButtons button )
00258 {
00259 performWindowOperation( options()->operationMaxButtonClick( button ));
00260 }
00261
00262 void KDecoration::maximize( MaximizeMode mode )
00263 {
00264 bridge_->maximize( mode );
00265 }
00266
00267 void KDecoration::minimize()
00268 {
00269 bridge_->minimize();
00270 }
00271
00272 void KDecoration::showContextHelp()
00273 {
00274 bridge_->showContextHelp();
00275 }
00276
00277 void KDecoration::setDesktop( int desktop )
00278 {
00279 bridge_->setDesktop( desktop );
00280 }
00281
00282 void KDecoration::toggleOnAllDesktops()
00283 {
00284 if( isOnAllDesktops())
00285 setDesktop( bridge_->currentDesktop());
00286 else
00287 setDesktop( NET::OnAllDesktops );
00288 }
00289
00290 void KDecoration::titlebarDblClickOperation()
00291 {
00292 bridge_->titlebarDblClickOperation();
00293 }
00294
00295 void KDecoration::titlebarMouseWheelOperation( int delta )
00296 {
00297 bridge_->titlebarMouseWheelOperation( delta );
00298 }
00299
00300 void KDecoration::setShade( bool set )
00301 {
00302 bridge_->setShade( set );
00303 }
00304
00305 void KDecoration::setKeepAbove( bool set )
00306 {
00307 bridge_->setKeepAbove( set );
00308 }
00309
00310 void KDecoration::setKeepBelow( bool set )
00311 {
00312 bridge_->setKeepBelow( set );
00313 }
00314
00315 void KDecoration::emitKeepAboveChanged( bool above )
00316 {
00317 keepAboveChanged( above );
00318 }
00319
00320 void KDecoration::emitKeepBelowChanged( bool below )
00321 {
00322 keepBelowChanged( below );
00323 }
00324
00325 bool KDecoration::drawbound( const QRect&, bool )
00326 {
00327 return false;
00328 }
00329
00330 bool KDecoration::windowDocked( Position )
00331 {
00332 return false;
00333 }
00334
00335 void KDecoration::reset( unsigned long )
00336 {
00337 }
00338
00339 void KDecoration::grabXServer()
00340 {
00341 bridge_->grabXServer( true );
00342 }
00343
00344 void KDecoration::ungrabXServer()
00345 {
00346 bridge_->grabXServer( false );
00347 }
00348
00349 KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
00350 {
00351 const int range = 16;
00352 int bleft, bright, btop, bbottom;
00353 borders( bleft, bright, btop, bbottom );
00354 btop = qMin( btop, 4 );
00355
00356 Position m = PositionCenter;
00357
00358 if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
00359 && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
00360 return PositionCenter;
00361
00362 if ( p.y() <= qMax( range, btop ) && p.x() <= qMax( range, bleft ))
00363 m = PositionTopLeft;
00364 else if ( p.y() >= widget()->height()- qMax( range, bbottom )
00365 && p.x() >= widget()->width()- qMax( range, bright ))
00366 m = PositionBottomRight;
00367 else if ( p.y() >= widget()->height()- qMax( range, bbottom ) && p.x() <= qMax( range, bleft ))
00368 m = PositionBottomLeft;
00369 else if ( p.y() <= qMax( range, btop ) && p.x() >= widget()->width()- qMax( range, bright ))
00370 m = PositionTopRight;
00371 else if ( p.y() <= btop )
00372 m = PositionTop;
00373 else if ( p.y() >= widget()->height()-bbottom )
00374 m = PositionBottom;
00375 else if ( p.x() <= bleft )
00376 m = PositionLeft;
00377 else if ( p.x() >= widget()->width()-bright )
00378 m = PositionRight;
00379 else
00380 m = PositionCenter;
00381 return m;
00382 }
00383
00384 KDecorationOptions::KDecorationOptions()
00385 : d( new KDecorationOptionsPrivate )
00386 {
00387 assert( KDecoration::options_ == NULL );
00388 KDecoration::options_ = this;
00389 }
00390
00391 KDecorationOptions::~KDecorationOptions()
00392 {
00393 assert( KDecoration::options_ == this );
00394 KDecoration::options_ = NULL;
00395 delete d;
00396 }
00397
00398 QColor KDecorationOptions::color(ColorType type, bool active) const
00399 {
00400 return(d->colors[type + (active ? 0 : NUM_COLORS)]);
00401 }
00402
00403 QFont KDecorationOptions::font(bool active, bool small) const
00404 {
00405 if ( small )
00406 return(active ? d->activeFontSmall : d->inactiveFontSmall);
00407 else
00408 return(active ? d->activeFont : d->inactiveFont);
00409 }
00410
00411 QPalette KDecorationOptions::palette(ColorType type, bool active) const
00412 {
00413 int idx = type + (active ? 0 : NUM_COLORS);
00414 if(d->pal[idx])
00415 return(*d->pal[idx]);
00416 #ifdef __GNUC__
00417 #warning KDE4 : why construct the palette this way?
00418 #endif
00419
00420
00421
00422
00423
00424 d->pal[idx] = new QPalette(d->colors[idx]);
00425 return(*d->pal[idx]);
00426 }
00427
00428 unsigned long KDecorationOptions::updateSettings( KConfig* config )
00429 {
00430 return d->updateSettings( config );
00431 }
00432
00433 bool KDecorationOptions::customButtonPositions() const
00434 {
00435 return d->custom_button_positions;
00436 }
00437
00438 QString KDecorationOptions::titleButtonsLeft() const
00439 {
00440 return d->title_buttons_left;
00441 }
00442
00443 QString KDecorationOptions::defaultTitleButtonsLeft()
00444 {
00445 return "MS";
00446 }
00447
00448 QString KDecorationOptions::titleButtonsRight() const
00449 {
00450 return d->title_buttons_right;
00451 }
00452
00453 QString KDecorationOptions::defaultTitleButtonsRight()
00454 {
00455 return "HIA__X";
00456 }
00457
00458 bool KDecorationOptions::showTooltips() const
00459 {
00460 return d->show_tooltips;
00461 }
00462
00463 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
00464 {
00465 assert( factory != NULL );
00466 if( d->cached_border_size == BordersCount )
00467 d->cached_border_size = d->findPreferredBorderSize( d->border_size,
00468 factory->borderSizes());
00469 return d->cached_border_size;
00470 }
00471
00472 bool KDecorationOptions::moveResizeMaximizedWindows() const
00473 {
00474 return d->move_resize_maximized_windows;
00475 }
00476
00477 KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::MouseButtons button ) const
00478 {
00479 return button == Qt::RightButton? d->opMaxButtonRightClick :
00480 button == Qt::MidButton? d->opMaxButtonMiddleClick :
00481 d->opMaxButtonLeftClick;
00482 }
00483
00484 void KDecorationOptions::setOpMaxButtonLeftClick( WindowOperation op )
00485 {
00486 d->opMaxButtonLeftClick = op;
00487 }
00488
00489 void KDecorationOptions::setOpMaxButtonRightClick( WindowOperation op )
00490 {
00491 d->opMaxButtonRightClick = op;
00492 }
00493
00494 void KDecorationOptions::setOpMaxButtonMiddleClick( WindowOperation op )
00495 {
00496 d->opMaxButtonMiddleClick = op;
00497 }
00498
00499 void KDecorationOptions::setBorderSize( BorderSize bs )
00500 {
00501 d->border_size = bs;
00502 d->cached_border_size = BordersCount;
00503 }
00504
00505 void KDecorationOptions::setCustomButtonPositions( bool b )
00506 {
00507 d->custom_button_positions = b;
00508 }
00509
00510 void KDecorationOptions::setTitleButtonsLeft( const QString& b )
00511 {
00512 d->title_buttons_left = b;
00513 }
00514
00515 void KDecorationOptions::setTitleButtonsRight( const QString& b )
00516 {
00517 d->title_buttons_right = b;
00518 }
00519
00520 #include "kdecoration.moc"