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 if ( options()->showTooltips() )
00086 w->setAttribute( Qt::WA_AlwaysShowToolTips );
00087 setMainWidget(w);
00088 }
00089
00090 void KDecoration::setMainWidget( QWidget* w )
00091 {
00092 assert( w_ == NULL );
00093 w_ = w;
00094 w->setMouseTracking( true );
00095 widget()->resize( geometry().size());
00096 }
00097
00098 QWidget* KDecoration::initialParentWidget() const
00099 {
00100 return bridge_->initialParentWidget();
00101 }
00102
00103 Qt::WFlags KDecoration::initialWFlags() const
00104 {
00105 return bridge_->initialWFlags();
00106 }
00107
00108 bool KDecoration::isActive() const
00109 {
00110 return bridge_->isActive();
00111 }
00112
00113 bool KDecoration::isCloseable() const
00114 {
00115 return bridge_->isCloseable();
00116 }
00117
00118 bool KDecoration::isMaximizable() const
00119 {
00120 return bridge_->isMaximizable();
00121 }
00122
00123 KDecoration::MaximizeMode KDecoration::maximizeMode() const
00124 {
00125 return bridge_->maximizeMode();
00126 }
00127
00128 bool KDecoration::isMinimizable() const
00129 {
00130 return bridge_->isMinimizable();
00131 }
00132
00133 bool KDecoration::providesContextHelp() const
00134 {
00135 return bridge_->providesContextHelp();
00136 }
00137
00138 int KDecoration::desktop() const
00139 {
00140 return bridge_->desktop();
00141 }
00142
00143 bool KDecoration::isModal() const
00144 {
00145 return bridge_->isModal();
00146 }
00147
00148 bool KDecoration::isShadeable() const
00149 {
00150 return bridge_->isShadeable();
00151 }
00152
00153 bool KDecoration::isShade() const
00154 {
00155 return bridge_->isShade();
00156 }
00157
00158 bool KDecoration::isSetShade() const
00159 {
00160 return bridge_->isSetShade();
00161 }
00162
00163 bool KDecoration::keepAbove() const
00164 {
00165 return bridge_->keepAbove();
00166 }
00167
00168 bool KDecoration::keepBelow() const
00169 {
00170 return bridge_->keepBelow();
00171 }
00172
00173 bool KDecoration::isMovable() const
00174 {
00175 return bridge_->isMovable();
00176 }
00177
00178 bool KDecoration::isResizable() const
00179 {
00180 return bridge_->isResizable();
00181 }
00182
00183 NET::WindowType KDecoration::windowType( unsigned long supported_types ) const
00184 {
00185 return bridge_->windowType( supported_types );
00186 }
00187
00188 QIcon KDecoration::icon() const
00189 {
00190 return bridge_->icon();
00191 }
00192
00193 QString KDecoration::caption() const
00194 {
00195 return bridge_->caption();
00196 }
00197
00198 void KDecoration::processMousePressEvent( QMouseEvent* e )
00199 {
00200 return bridge_->processMousePressEvent( e );
00201 }
00202
00203 void KDecoration::showWindowMenu( const QRect &pos )
00204 {
00205 bridge_->showWindowMenu( pos );
00206 }
00207
00208 void KDecoration::showWindowMenu( QPoint pos )
00209 {
00210 bridge_->showWindowMenu( pos );
00211 }
00212
00213 void KDecoration::performWindowOperation( WindowOperation op )
00214 {
00215 bridge_->performWindowOperation( op );
00216 }
00217
00218 void KDecoration::setMask( const QRegion& reg, int mode )
00219 {
00220 bridge_->setMask( reg, mode );
00221 }
00222
00223 void KDecoration::clearMask()
00224 {
00225 bridge_->setMask( QRegion(), 0 );
00226 }
00227
00228 bool KDecoration::isPreview() const
00229 {
00230 return bridge_->isPreview();
00231 }
00232
00233 QRect KDecoration::geometry() const
00234 {
00235 return bridge_->geometry();
00236 }
00237
00238 QRect KDecoration::iconGeometry() const
00239 {
00240 return bridge_->iconGeometry();
00241 }
00242
00243 QRegion KDecoration::unobscuredRegion( const QRegion& r ) const
00244 {
00245 return bridge_->unobscuredRegion( r );
00246 }
00247
00248 WId KDecoration::windowId() const
00249 {
00250 return bridge_->windowId();
00251 }
00252
00253 void KDecoration::closeWindow()
00254 {
00255 bridge_->closeWindow();
00256 }
00257
00258 void KDecoration::maximize( Qt::MouseButtons button )
00259 {
00260 performWindowOperation( options()->operationMaxButtonClick( button ));
00261 }
00262
00263 void KDecoration::maximize( MaximizeMode mode )
00264 {
00265 bridge_->maximize( mode );
00266 }
00267
00268 void KDecoration::minimize()
00269 {
00270 bridge_->minimize();
00271 }
00272
00273 void KDecoration::showContextHelp()
00274 {
00275 bridge_->showContextHelp();
00276 }
00277
00278 void KDecoration::setDesktop( int desktop )
00279 {
00280 bridge_->setDesktop( desktop );
00281 }
00282
00283 void KDecoration::toggleOnAllDesktops()
00284 {
00285 if( isOnAllDesktops())
00286 setDesktop( bridge_->currentDesktop());
00287 else
00288 setDesktop( NET::OnAllDesktops );
00289 }
00290
00291 void KDecoration::titlebarDblClickOperation()
00292 {
00293 bridge_->titlebarDblClickOperation();
00294 }
00295
00296 void KDecoration::titlebarMouseWheelOperation( int delta )
00297 {
00298 bridge_->titlebarMouseWheelOperation( delta );
00299 }
00300
00301 void KDecoration::setShade( bool set )
00302 {
00303 bridge_->setShade( set );
00304 }
00305
00306 void KDecoration::setKeepAbove( bool set )
00307 {
00308 bridge_->setKeepAbove( set );
00309 }
00310
00311 void KDecoration::setKeepBelow( bool set )
00312 {
00313 bridge_->setKeepBelow( set );
00314 }
00315
00316 void KDecoration::emitKeepAboveChanged( bool above )
00317 {
00318 keepAboveChanged( above );
00319 }
00320
00321 void KDecoration::emitKeepBelowChanged( bool below )
00322 {
00323 keepBelowChanged( below );
00324 }
00325
00326 bool KDecoration::drawbound( const QRect&, bool )
00327 {
00328 return false;
00329 }
00330
00331 bool KDecoration::windowDocked( Position )
00332 {
00333 return false;
00334 }
00335
00336 void KDecoration::reset( unsigned long )
00337 {
00338 }
00339
00340 void KDecoration::grabXServer()
00341 {
00342 bridge_->grabXServer( true );
00343 }
00344
00345 void KDecoration::ungrabXServer()
00346 {
00347 bridge_->grabXServer( false );
00348 }
00349
00350 KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
00351 {
00352 const int range = 16;
00353 int bleft, bright, btop, bbottom;
00354 borders( bleft, bright, btop, bbottom );
00355 btop = qMin( btop, 4 );
00356
00357 Position m = PositionCenter;
00358
00359 if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
00360 && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
00361 return PositionCenter;
00362
00363 if ( p.y() <= qMax( range, btop ) && p.x() <= qMax( range, bleft ))
00364 m = PositionTopLeft;
00365 else if ( p.y() >= widget()->height()- qMax( range, bbottom )
00366 && p.x() >= widget()->width()- qMax( range, bright ))
00367 m = PositionBottomRight;
00368 else if ( p.y() >= widget()->height()- qMax( range, bbottom ) && p.x() <= qMax( range, bleft ))
00369 m = PositionBottomLeft;
00370 else if ( p.y() <= qMax( range, btop ) && p.x() >= widget()->width()- qMax( range, bright ))
00371 m = PositionTopRight;
00372 else if ( p.y() <= btop )
00373 m = PositionTop;
00374 else if ( p.y() >= widget()->height()-bbottom )
00375 m = PositionBottom;
00376 else if ( p.x() <= bleft )
00377 m = PositionLeft;
00378 else if ( p.x() >= widget()->width()-bright )
00379 m = PositionRight;
00380 else
00381 m = PositionCenter;
00382 return m;
00383 }
00384
00385
00386 KDecorationUnstable::KDecorationUnstable( KDecorationBridge* bridge, KDecorationFactory* factory )
00387 : KDecoration( bridge, factory )
00388 {
00389 Q_ASSERT( dynamic_cast< KDecorationBridgeUnstable* >( bridge ));
00390 }
00391
00392 KDecorationUnstable::~KDecorationUnstable()
00393 {
00394 }
00395
00396 QList<QRect> KDecorationUnstable::shadowQuads( ShadowType type ) const
00397 {
00398 Q_UNUSED( type );
00399 return QList<QRect>();
00400 }
00401
00402 double KDecorationUnstable::shadowOpacity( ShadowType type ) const
00403 {
00404 if( isActive() && type == ShadowBorderedActive )
00405 return 1.0;
00406 else if( !isActive() && type == ShadowBorderedInactive )
00407 return 1.0;
00408 return 0.0;
00409 }
00410
00411 double KDecorationUnstable::shadowBrightness( ShadowType type ) const
00412 {
00413 Q_UNUSED( type );
00414 return 1.0;
00415 }
00416
00417 double KDecorationUnstable::shadowSaturation( ShadowType type ) const
00418 {
00419 Q_UNUSED( type );
00420 return 1.0;
00421 }
00422
00423 void KDecorationUnstable::repaintShadow()
00424 {
00425 static_cast< KDecorationBridgeUnstable* >( bridge_ )->repaintShadow();
00426 }
00427
00428 bool KDecorationUnstable::compositingActive() const
00429 {
00430 return static_cast< KDecorationBridgeUnstable* >( bridge_ )->compositingActive();
00431 }
00432
00433 bool KDecorationUnstable::shadowsActive() const
00434 {
00435 return static_cast< KDecorationBridgeUnstable* >( bridge_ )->shadowsActive();
00436 }
00437
00438 double KDecorationUnstable::opacity() const
00439 {
00440 return static_cast< KDecorationBridgeUnstable* >( bridge_ )->opacity();
00441 }
00442
00443
00444 KDecorationOptions::KDecorationOptions()
00445 : d( new KDecorationOptionsPrivate )
00446 {
00447 assert( KDecoration::options_ == NULL );
00448 KDecoration::options_ = this;
00449 }
00450
00451 KDecorationOptions::~KDecorationOptions()
00452 {
00453 assert( KDecoration::options_ == this );
00454 KDecoration::options_ = NULL;
00455 delete d;
00456 }
00457
00458 QColor KDecorationOptions::color(ColorType type, bool active) const
00459 {
00460 return(d->colors[type + (active ? 0 : NUM_COLORS)]);
00461 }
00462
00463 QFont KDecorationOptions::font(bool active, bool small) const
00464 {
00465 if ( small )
00466 return(active ? d->activeFontSmall : d->inactiveFontSmall);
00467 else
00468 return(active ? d->activeFont : d->inactiveFont);
00469 }
00470
00471 QPalette KDecorationOptions::palette(ColorType type, bool active) const
00472 {
00473 int idx = type + (active ? 0 : NUM_COLORS);
00474 if(d->pal[idx])
00475 return(*d->pal[idx]);
00476 #ifdef __GNUC__
00477 #warning KDE4 : why construct the palette this way?
00478 #endif
00479
00480
00481
00482
00483
00484 d->pal[idx] = new QPalette(d->colors[idx]);
00485 return(*d->pal[idx]);
00486 }
00487
00488 unsigned long KDecorationOptions::updateSettings( KConfig* config )
00489 {
00490 return d->updateSettings( config );
00491 }
00492
00493 bool KDecorationOptions::customButtonPositions() const
00494 {
00495 return d->custom_button_positions;
00496 }
00497
00498 QString KDecorationOptions::titleButtonsLeft() const
00499 {
00500 return d->title_buttons_left;
00501 }
00502
00503 QString KDecorationOptions::defaultTitleButtonsLeft()
00504 {
00505 return "MS";
00506 }
00507
00508 QString KDecorationOptions::titleButtonsRight() const
00509 {
00510 return d->title_buttons_right;
00511 }
00512
00513 QString KDecorationOptions::defaultTitleButtonsRight()
00514 {
00515 return "HIA__X";
00516 }
00517
00518 bool KDecorationOptions::showTooltips() const
00519 {
00520 return d->show_tooltips;
00521 }
00522
00523 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
00524 {
00525 assert( factory != NULL );
00526 if( d->cached_border_size == BordersCount )
00527 d->cached_border_size = d->findPreferredBorderSize( d->border_size,
00528 factory->borderSizes());
00529 return d->cached_border_size;
00530 }
00531
00532 bool KDecorationOptions::moveResizeMaximizedWindows() const
00533 {
00534 return d->move_resize_maximized_windows;
00535 }
00536
00537 KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::MouseButtons button ) const
00538 {
00539 return button == Qt::RightButton? d->opMaxButtonRightClick :
00540 button == Qt::MidButton? d->opMaxButtonMiddleClick :
00541 d->opMaxButtonLeftClick;
00542 }
00543
00544 void KDecorationOptions::setOpMaxButtonLeftClick( WindowOperation op )
00545 {
00546 d->opMaxButtonLeftClick = op;
00547 }
00548
00549 void KDecorationOptions::setOpMaxButtonRightClick( WindowOperation op )
00550 {
00551 d->opMaxButtonRightClick = op;
00552 }
00553
00554 void KDecorationOptions::setOpMaxButtonMiddleClick( WindowOperation op )
00555 {
00556 d->opMaxButtonMiddleClick = op;
00557 }
00558
00559 void KDecorationOptions::setBorderSize( BorderSize bs )
00560 {
00561 d->border_size = bs;
00562 d->cached_border_size = BordersCount;
00563 }
00564
00565 void KDecorationOptions::setCustomButtonPositions( bool b )
00566 {
00567 d->custom_button_positions = b;
00568 }
00569
00570 void KDecorationOptions::setTitleButtonsLeft( const QString& b )
00571 {
00572 d->title_buttons_left = b;
00573 }
00574
00575 void KDecorationOptions::setTitleButtonsRight( const QString& b )
00576 {
00577 d->title_buttons_right = b;
00578 }
00579
00580 #include "kdecoration.moc"