00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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];
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
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
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
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
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;
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 )
00180 return r;
00181 else
00182 {
00183
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( const QRect &)
00305 {
00306 }
00307
00308 void KDecorationPreviewBridge::showWindowMenu( QPoint )
00309 {
00310 }
00311
00312 void KDecorationPreviewBridge::performWindowOperation( WindowOperation )
00313 {
00314 }
00315
00316 void KDecorationPreviewBridge::setMask( const QRegion& reg, int mode )
00317 {
00318 preview->setPreviewMask( reg, mode, active );
00319 }
00320
00321 bool KDecorationPreviewBridge::isPreview() const
00322 {
00323 return true;
00324 }
00325
00326 QRect KDecorationPreviewBridge::geometry() const
00327 {
00328 return preview->windowGeometry( active );
00329 }
00330
00331 QRect KDecorationPreviewBridge::iconGeometry() const
00332 {
00333 return QRect();
00334 }
00335
00336 QRegion KDecorationPreviewBridge::unobscuredRegion( const QRegion& r ) const
00337 {
00338 return preview->unobscuredRegion( active, r );
00339 }
00340
00341 QWidget* KDecorationPreviewBridge::workspaceWidget() const
00342 {
00343 return preview;
00344 }
00345
00346 void KDecorationPreviewBridge::closeWindow()
00347 {
00348 }
00349
00350 void KDecorationPreviewBridge::maximize( MaximizeMode )
00351 {
00352 }
00353
00354 void KDecorationPreviewBridge::minimize()
00355 {
00356 }
00357
00358 void KDecorationPreviewBridge::showContextHelp()
00359 {
00360 }
00361
00362 void KDecorationPreviewBridge::setDesktop( int )
00363 {
00364 }
00365
00366 void KDecorationPreviewBridge::titlebarDblClickOperation()
00367 {
00368 }
00369
00370 void KDecorationPreviewBridge::setShade( bool )
00371 {
00372 }
00373
00374 void KDecorationPreviewBridge::setKeepAbove( bool )
00375 {
00376 }
00377
00378 void KDecorationPreviewBridge::setKeepBelow( bool )
00379 {
00380 }
00381
00382 int KDecorationPreviewBridge::currentDesktop() const
00383 {
00384 return 1;
00385 }
00386
00387 void KDecorationPreviewBridge::helperShowHide( bool )
00388 {
00389 }
00390
00391 void KDecorationPreviewBridge::grabXServer( bool )
00392 {
00393 }
00394
00395 KDecorationPreviewOptions::KDecorationPreviewOptions()
00396 {
00397 d = new KDecorationOptionsPrivate;
00398 d->defaultKWinSettings();
00399 updateSettings();
00400 }
00401
00402 KDecorationPreviewOptions::~KDecorationPreviewOptions()
00403 {
00404 delete d;
00405 }
00406
00407 unsigned long KDecorationPreviewOptions::updateSettings()
00408 {
00409 KConfig cfg( "kwinrc", true );
00410 unsigned long changed = 0;
00411 changed |= d->updateKWinSettings( &cfg );
00412 return changed;
00413 }
00414
00415 bool KDecorationPreviewPlugins::provides( Requirement )
00416 {
00417 return false;
00418 }
00419
00420 #include "preview.moc"