kwin Library API Documentation

preview.cpp

00001 /* 00002 * 00003 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #include "preview.h" 00021 00022 #include <kapplication.h> 00023 #include <klocale.h> 00024 #include <kconfig.h> 00025 #include <kglobal.h> 00026 #include <qlabel.h> 00027 #include <qstyle.h> 00028 #include <kiconloader.h> 00029 00030 #include <X11/Xlib.h> 00031 #include <X11/extensions/shape.h> 00032 00033 #include <kdecoration_plugins_p.h> 00034 00035 // FRAME the preview doesn't update to reflect the changes done in the kcm 00036 00037 KDecorationPreview::KDecorationPreview( QWidget* parent, const char* name ) 00038 : QWidget( parent, name ) 00039 { 00040 options = new KDecorationPreviewOptions; 00041 00042 bridge[Active] = new KDecorationPreviewBridge( this, true ); 00043 bridge[Inactive] = new KDecorationPreviewBridge( this, false ); 00044 00045 deco[Active] = deco[Inactive] = NULL; 00046 00047 no_preview = new QLabel( i18n( "No preview available.\n" 00048 "Most probably there\n" 00049 "was a problem loading the plugin." ), this ); 00050 00051 no_preview->setAlignment( AlignCenter ); 00052 00053 setMinimumSize( 100, 100 ); 00054 no_preview->resize( size()); 00055 } 00056 00057 KDecorationPreview::~KDecorationPreview() 00058 { 00059 for ( int i = 0; i < NumWindows; i++ ) 00060 { 00061 delete deco[i]; 00062 delete bridge[i]; 00063 } 00064 delete options; 00065 } 00066 00067 bool KDecorationPreview::recreateDecoration( KDecorationPlugins* plugins ) 00068 { 00069 for ( int i = 0; i < NumWindows; i++ ) 00070 { 00071 delete deco[i]; // deletes also window 00072 deco[i] = plugins->createDecoration( bridge[i] ); 00073 deco[i]->init(); 00074 } 00075 00076 if( deco[Active] == NULL || deco[Inactive] == NULL ) 00077 { 00078 return false; 00079 } 00080 00081 positionPreviews(); 00082 deco[Inactive]->widget()->show(); 00083 deco[Active]->widget()->show(); 00084 00085 return true; 00086 } 00087 00088 void KDecorationPreview::enablePreview() 00089 { 00090 no_preview->hide(); 00091 } 00092 00093 void KDecorationPreview::disablePreview() 00094 { 00095 delete deco[Active]; 00096 delete deco[Inactive]; 00097 deco[Active] = deco[Inactive] = NULL; 00098 no_preview->show(); 00099 } 00100 00101 void KDecorationPreview::resizeEvent( QResizeEvent* e ) 00102 { 00103 QWidget::resizeEvent( e ); 00104 positionPreviews(); 00105 } 00106 00107 void KDecorationPreview::positionPreviews() 00108 { 00109 int titleBarHeight, leftBorder, rightBorder, xoffset, 00110 dummy1, dummy2, dummy3; 00111 QRect geometry; 00112 QSize size; 00113 00114 no_preview->resize( this->size() ); 00115 00116 if ( !deco[Active] || !deco[Inactive] ) 00117 return; 00118 00119 // don't have more than one reference to the same dummy variable in one borders() call. 00120 deco[Active]->borders( dummy1, dummy2, titleBarHeight, dummy3 ); 00121 deco[Inactive]->borders( leftBorder, rightBorder, dummy1, dummy2 ); 00122 00123 titleBarHeight = kMin( int( titleBarHeight * .9 ), 30 ); 00124 xoffset = kMin( kMax( 10, QApplication::reverseLayout() 00125 ? leftBorder : rightBorder ), 30 ); 00126 00127 // Resize the active window 00128 size = QSize( width() - xoffset, height() - titleBarHeight ) 00129 .expandedTo( deco[Active]->minimumSize() ); 00130 geometry = QRect( QPoint( 0, titleBarHeight ), size ); 00131 deco[Active]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); 00132 00133 // Resize the inactive window 00134 size = QSize( width() - xoffset, height() - titleBarHeight ) 00135 .expandedTo( deco[Inactive]->minimumSize() ); 00136 geometry = QRect( QPoint( xoffset, 0 ), size ); 00137 deco[Inactive]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); 00138 } 00139 00140 void KDecorationPreview::setPreviewMask( const QRegion& reg, int mode, bool active ) 00141 { 00142 QWidget *widget = active ? deco[Active]->widget() : deco[Inactive]->widget(); 00143 00144 // FRAME duped from client.cpp 00145 if( mode == Unsorted ) 00146 { 00147 XShapeCombineRegion( qt_xdisplay(), widget->winId(), ShapeBounding, 0, 0, 00148 reg.handle(), ShapeSet ); 00149 } 00150 else 00151 { 00152 QMemArray< QRect > rects = reg.rects(); 00153 XRectangle* xrects = new XRectangle[ rects.count() ]; 00154 for( unsigned int i = 0; 00155 i < rects.count(); 00156 ++i ) 00157 { 00158 xrects[ i ].x = rects[ i ].x(); 00159 xrects[ i ].y = rects[ i ].y(); 00160 xrects[ i ].width = rects[ i ].width(); 00161 xrects[ i ].height = rects[ i ].height(); 00162 } 00163 XShapeCombineRectangles( qt_xdisplay(), widget->winId(), ShapeBounding, 0, 0, 00164 xrects, rects.count(), ShapeSet, mode ); 00165 delete[] xrects; 00166 } 00167 if( active ) 00168 mask = reg; // keep shape of the active window for unobscuredRegion() 00169 } 00170 00171 QRect KDecorationPreview::windowGeometry( bool active ) const 00172 { 00173 QWidget *widget = active ? deco[Active]->widget() : deco[Inactive]->widget(); 00174 return widget->geometry(); 00175 } 00176 00177 QRegion KDecorationPreview::unobscuredRegion( bool active, const QRegion& r ) const 00178 { 00179 if( active ) // this one is not obscured 00180 return r; 00181 else 00182 { 00183 // copied from KWin core's code 00184 QRegion ret = r; 00185 QRegion r2 = mask; 00186 if( r2.isEmpty()) 00187 r2 = QRegion( windowGeometry( true )); 00188 r2.translate( windowGeometry( true ).x() - windowGeometry( false ).x(), 00189 windowGeometry( true ).y() - windowGeometry( false ).y()); 00190 ret -= r2; 00191 return ret; 00192 } 00193 } 00194 00195 KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview* p, bool a ) 00196 : preview( p ), active( a ) 00197 { 00198 } 00199 00200 QWidget* KDecorationPreviewBridge::initialParentWidget() const 00201 { 00202 return preview; 00203 } 00204 00205 Qt::WFlags KDecorationPreviewBridge::initialWFlags() const 00206 { 00207 return 0; 00208 } 00209 00210 bool KDecorationPreviewBridge::isActive() const 00211 { 00212 return active; 00213 } 00214 00215 bool KDecorationPreviewBridge::isCloseable() const 00216 { 00217 return true; 00218 } 00219 00220 bool KDecorationPreviewBridge::isMaximizable() const 00221 { 00222 return true; 00223 } 00224 00225 KDecoration::MaximizeMode KDecorationPreviewBridge::maximizeMode() const 00226 { 00227 return KDecoration::MaximizeRestore; 00228 } 00229 00230 bool KDecorationPreviewBridge::isMinimizable() const 00231 { 00232 return true; 00233 } 00234 00235 bool KDecorationPreviewBridge::providesContextHelp() const 00236 { 00237 return true; 00238 } 00239 00240 int KDecorationPreviewBridge::desktop() const 00241 { 00242 return 1; 00243 } 00244 00245 bool KDecorationPreviewBridge::isModal() const 00246 { 00247 return false; 00248 } 00249 00250 bool KDecorationPreviewBridge::isShadeable() const 00251 { 00252 return true; 00253 } 00254 00255 bool KDecorationPreviewBridge::isShade() const 00256 { 00257 return false; 00258 } 00259 00260 bool KDecorationPreviewBridge::isSetShade() const 00261 { 00262 return false; 00263 } 00264 00265 bool KDecorationPreviewBridge::keepAbove() const 00266 { 00267 return false; 00268 } 00269 00270 bool KDecorationPreviewBridge::keepBelow() const 00271 { 00272 return false; 00273 } 00274 00275 bool KDecorationPreviewBridge::isMovable() const 00276 { 00277 return true; 00278 } 00279 00280 bool KDecorationPreviewBridge::isResizable() const 00281 { 00282 return true; 00283 } 00284 00285 NET::WindowType KDecorationPreviewBridge::windowType( unsigned long ) const 00286 { 00287 return NET::Normal; 00288 } 00289 00290 QIconSet KDecorationPreviewBridge::icon() const 00291 { 00292 return SmallIconSet( "xapp" ); 00293 } 00294 00295 QString KDecorationPreviewBridge::caption() const 00296 { 00297 return active ? i18n( "Active window" ) : i18n( "Inactive window" ); 00298 } 00299 00300 void KDecorationPreviewBridge::processMousePressEvent( QMouseEvent* ) 00301 { 00302 } 00303 00304 void KDecorationPreviewBridge::showWindowMenu( QPoint ) 00305 { 00306 } 00307 00308 void KDecorationPreviewBridge::performWindowOperation( WindowOperation ) 00309 { 00310 } 00311 00312 void KDecorationPreviewBridge::setMask( const QRegion& reg, int mode ) 00313 { 00314 preview->setPreviewMask( reg, mode, active ); 00315 } 00316 00317 bool KDecorationPreviewBridge::isPreview() const 00318 { 00319 return true; 00320 } 00321 00322 QRect KDecorationPreviewBridge::geometry() const 00323 { 00324 return preview->windowGeometry( active ); 00325 } 00326 00327 QRect KDecorationPreviewBridge::iconGeometry() const 00328 { 00329 return QRect(); 00330 } 00331 00332 QRegion KDecorationPreviewBridge::unobscuredRegion( const QRegion& r ) const 00333 { 00334 return preview->unobscuredRegion( active, r ); 00335 } 00336 00337 QWidget* KDecorationPreviewBridge::workspaceWidget() const 00338 { 00339 return preview; 00340 } 00341 00342 void KDecorationPreviewBridge::closeWindow() 00343 { 00344 } 00345 00346 void KDecorationPreviewBridge::maximize( MaximizeMode ) 00347 { 00348 } 00349 00350 void KDecorationPreviewBridge::minimize() 00351 { 00352 } 00353 00354 void KDecorationPreviewBridge::showContextHelp() 00355 { 00356 } 00357 00358 void KDecorationPreviewBridge::setDesktop( int ) 00359 { 00360 } 00361 00362 void KDecorationPreviewBridge::titlebarDblClickOperation() 00363 { 00364 } 00365 00366 void KDecorationPreviewBridge::setShade( bool ) 00367 { 00368 } 00369 00370 void KDecorationPreviewBridge::setKeepAbove( bool ) 00371 { 00372 } 00373 00374 void KDecorationPreviewBridge::setKeepBelow( bool ) 00375 { 00376 } 00377 00378 int KDecorationPreviewBridge::currentDesktop() const 00379 { 00380 return 1; 00381 } 00382 00383 void KDecorationPreviewBridge::helperShowHide( bool ) 00384 { 00385 } 00386 00387 void KDecorationPreviewBridge::grabXServer( bool ) 00388 { 00389 } 00390 00391 KDecorationPreviewOptions::KDecorationPreviewOptions() 00392 { 00393 d = new KDecorationOptionsPrivate; 00394 d->defaultKWinSettings(); 00395 updateSettings(); 00396 } 00397 00398 KDecorationPreviewOptions::~KDecorationPreviewOptions() 00399 { 00400 delete d; 00401 } 00402 00403 unsigned long KDecorationPreviewOptions::updateSettings() 00404 { 00405 KConfig cfg( "kwinrc", true ); 00406 unsigned long changed = 0; 00407 changed |= d->updateKWinSettings( &cfg ); 00408 return changed; 00409 } 00410 00411 bool KDecorationPreviewPlugins::provides( Requirement ) 00412 { 00413 return false; 00414 } 00415 00416 #include "preview.moc"
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Dec 16 19:08:41 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003