Make it possible to use KDecorationOptions without private headers.

svn path=/trunk/KDE/kdebase/workspace/; revision=768271
This commit is contained in:
Luboš Luňák 2008-01-29 16:44:41 +00:00
parent 4b792d000e
commit 685e1d2361
12 changed files with 132 additions and 74 deletions

View file

@ -436,36 +436,32 @@ KDecorationPreviewOptions::KDecorationPreviewOptions()
customButtons = true; customButtons = true;
customTitleButtonsLeft.clear(); // invalid customTitleButtonsLeft.clear(); // invalid
customTitleButtonsRight.clear(); // invalid customTitleButtonsRight.clear(); // invalid
d = new KDecorationOptionsPrivate;
d->defaultKWinSettings();
updateSettings(); updateSettings();
} }
KDecorationPreviewOptions::~KDecorationPreviewOptions() KDecorationPreviewOptions::~KDecorationPreviewOptions()
{ {
delete d;
} }
unsigned long KDecorationPreviewOptions::updateSettings() unsigned long KDecorationPreviewOptions::updateSettings()
{ {
KConfig cfg( "kwinrc" ); KConfig cfg( "kwinrc" );
unsigned long changed = 0; unsigned long changed = 0;
changed |= d->updateKWinSettings( &cfg ); changed |= KDecorationOptions::updateSettings( &cfg );
// set custom border size/buttons // set custom border size/buttons
if (customBorderSize != BordersCount) if (customBorderSize != BordersCount)
d->border_size = customBorderSize; setBorderSize( customBorderSize );
if (customButtonsChanged) if (customButtonsChanged)
d->custom_button_positions = customButtons; setCustomButtonPositions( customButtons );
if (customButtons) { if (customButtons) {
if (!customTitleButtonsLeft.isNull() ) if (!customTitleButtonsLeft.isNull() )
d->title_buttons_left = customTitleButtonsLeft; setTitleButtonsLeft( customTitleButtonsLeft );
if (!customTitleButtonsRight.isNull() ) if (!customTitleButtonsRight.isNull() )
d->title_buttons_right = customTitleButtonsRight; setTitleButtonsRight( customTitleButtonsRight );
} else { } else {
d->title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft(); setTitleButtonsLeft( KDecorationOptions::defaultTitleButtonsLeft());
d->title_buttons_right = KDecorationOptions::defaultTitleButtonsRight(); setTitleButtonsRight( KDecorationOptions::defaultTitleButtonsRight());
} }
return changed; return changed;

View file

@ -25,7 +25,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QLabel> #include <QLabel>
#include <QResizeEvent> #include <QResizeEvent>
#include <kdecoration_p.h> #include <kdecoration.h>
#include <kdecorationbridge.h> #include <kdecorationbridge.h>
#include <kdecoration_plugins_p.h> #include <kdecoration_plugins_p.h>

View file

@ -27,6 +27,10 @@
#include "kdecoration.h" #include "kdecoration.h"
//
// This header file is internal. I mean it.
//
class KCommonDecoration; class KCommonDecoration;
class KDecorationBridge; class KDecorationBridge;
class KDecorationFactory; class KDecorationFactory;

View file

@ -346,7 +346,7 @@ void KDecoration::ungrabXServer()
} }
KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
{ {
const int range = 16; const int range = 16;
int bleft, bright, btop, bbottom; int bleft, bright, btop, bbottom;
borders( bleft, bright, btop, bbottom ); borders( bleft, bright, btop, bbottom );
@ -378,9 +378,10 @@ KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
else else
m = PositionCenter; m = PositionCenter;
return m; return m;
} }
KDecorationOptions::KDecorationOptions() KDecorationOptions::KDecorationOptions()
: d( new KDecorationOptionsPrivate )
{ {
assert( KDecoration::options_ == NULL ); assert( KDecoration::options_ == NULL );
KDecoration::options_ = this; KDecoration::options_ = this;
@ -390,23 +391,24 @@ KDecorationOptions::~KDecorationOptions()
{ {
assert( KDecoration::options_ == this ); assert( KDecoration::options_ == this );
KDecoration::options_ = NULL; KDecoration::options_ = NULL;
delete d;
} }
QColor KDecorationOptions::color(ColorType type, bool active) const QColor KDecorationOptions::color(ColorType type, bool active) const
{ {
return(d->colors[type + (active ? 0 : NUM_COLORS)]); return(d->colors[type + (active ? 0 : NUM_COLORS)]);
} }
QFont KDecorationOptions::font(bool active, bool small) const QFont KDecorationOptions::font(bool active, bool small) const
{ {
if ( small ) if ( small )
return(active ? d->activeFontSmall : d->inactiveFontSmall); return(active ? d->activeFontSmall : d->inactiveFontSmall);
else else
return(active ? d->activeFont : d->inactiveFont); return(active ? d->activeFont : d->inactiveFont);
} }
QPalette KDecorationOptions::palette(ColorType type, bool active) const QPalette KDecorationOptions::palette(ColorType type, bool active) const
{ {
int idx = type + (active ? 0 : NUM_COLORS); int idx = type + (active ? 0 : NUM_COLORS);
if(d->pal[idx]) if(d->pal[idx])
return(*d->pal[idx]); return(*d->pal[idx]);
@ -420,56 +422,98 @@ QPalette KDecorationOptions::palette(ColorType type, bool active) const
// base()); // base());
d->pal[idx] = new QPalette(d->colors[idx]); d->pal[idx] = new QPalette(d->colors[idx]);
return(*d->pal[idx]); return(*d->pal[idx]);
} }
unsigned long KDecorationOptions::updateSettings( KConfig* config )
{
return d->updateSettings( config );
}
bool KDecorationOptions::customButtonPositions() const bool KDecorationOptions::customButtonPositions() const
{ {
return d->custom_button_positions; return d->custom_button_positions;
} }
QString KDecorationOptions::titleButtonsLeft() const QString KDecorationOptions::titleButtonsLeft() const
{ {
return d->title_buttons_left; return d->title_buttons_left;
} }
QString KDecorationOptions::defaultTitleButtonsLeft() QString KDecorationOptions::defaultTitleButtonsLeft()
{ {
return "MS"; return "MS";
} }
QString KDecorationOptions::titleButtonsRight() const QString KDecorationOptions::titleButtonsRight() const
{ {
return d->title_buttons_right; return d->title_buttons_right;
} }
QString KDecorationOptions::defaultTitleButtonsRight() QString KDecorationOptions::defaultTitleButtonsRight()
{ {
return "HIA__X"; return "HIA__X";
} }
bool KDecorationOptions::showTooltips() const bool KDecorationOptions::showTooltips() const
{ {
return d->show_tooltips; return d->show_tooltips;
} }
KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
{ {
assert( factory != NULL ); assert( factory != NULL );
if( d->cached_border_size == BordersCount ) // invalid if( d->cached_border_size == BordersCount ) // invalid
d->cached_border_size = d->findPreferredBorderSize( d->border_size, d->cached_border_size = d->findPreferredBorderSize( d->border_size,
factory->borderSizes()); factory->borderSizes());
return d->cached_border_size; return d->cached_border_size;
} }
bool KDecorationOptions::moveResizeMaximizedWindows() const bool KDecorationOptions::moveResizeMaximizedWindows() const
{ {
return d->move_resize_maximized_windows; return d->move_resize_maximized_windows;
} }
KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::MouseButtons button ) const KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::MouseButtons button ) const
{ {
return button == Qt::RightButton? d->OpMaxButtonRightClick : return button == Qt::RightButton? d->opMaxButtonRightClick :
button == Qt::MidButton? d->OpMaxButtonMiddleClick : button == Qt::MidButton? d->opMaxButtonMiddleClick :
d->OpMaxButtonLeftClick; d->opMaxButtonLeftClick;
} }
void KDecorationOptions::setOpMaxButtonLeftClick( WindowOperation op )
{
d->opMaxButtonLeftClick = op;
}
void KDecorationOptions::setOpMaxButtonRightClick( WindowOperation op )
{
d->opMaxButtonRightClick = op;
}
void KDecorationOptions::setOpMaxButtonMiddleClick( WindowOperation op )
{
d->opMaxButtonMiddleClick = op;
}
void KDecorationOptions::setBorderSize( BorderSize bs )
{
d->border_size = bs;
d->cached_border_size = BordersCount; // invalid
}
void KDecorationOptions::setCustomButtonPositions( bool b )
{
d->custom_button_positions = b;
}
void KDecorationOptions::setTitleButtonsLeft( const QString& b )
{
d->title_buttons_left = b;
}
void KDecorationOptions::setTitleButtonsRight( const QString& b )
{
d->title_buttons_right = b;
}
#include "kdecoration.moc" #include "kdecoration.moc"

View file

@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE.
#define KWIN_EXPORT KDE_EXPORT #define KWIN_EXPORT KDE_EXPORT
class KConfig;
/** @defgroup kdecoration KWin decorations library */ /** @defgroup kdecoration KWin decorations library */
/** @addtogroup kdecoration */ /** @addtogroup kdecoration */
@ -205,6 +207,12 @@ class KWIN_EXPORT KDecorationOptions : public KDecorationDefines
public: public:
KDecorationOptions(); KDecorationOptions();
virtual ~KDecorationOptions(); virtual ~KDecorationOptions();
/**
* Call to update settings when the config changes. Return value is
* a combination of Setting* (SettingColors, etc.) that have changed.
* @since 4.0.1
*/
unsigned long updateSettings( KConfig* config );
/** /**
* Returns the color that should be used for the given part of the decoration. * Returns the color that should be used for the given part of the decoration.
* The changed flags for this setting is SettingColors. * The changed flags for this setting is SettingColors.
@ -316,6 +324,21 @@ public:
virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask
protected: protected:
/** @internal */
void setOpMaxButtonLeftClick( WindowOperation op );
/** @internal */
void setOpMaxButtonRightClick( WindowOperation op );
/** @internal */
void setOpMaxButtonMiddleClick( WindowOperation op );
/** @internal */
void setBorderSize( BorderSize bs );
/** @internal */
void setCustomButtonPositions( bool b );
/** @internal */
void setTitleButtonsLeft( const QString& b );
/** @internal */
void setTitleButtonsRight( const QString& b );
private:
/** /**
* @internal * @internal
*/ */

View file

@ -32,6 +32,16 @@ DEALINGS IN THE SOFTWARE.
#include <assert.h> #include <assert.h>
KDecorationOptionsPrivate::KDecorationOptionsPrivate() KDecorationOptionsPrivate::KDecorationOptionsPrivate()
: title_buttons_left( KDecorationOptions::defaultTitleButtonsLeft())
, title_buttons_right( KDecorationOptions::defaultTitleButtonsRight())
, custom_button_positions( false )
, show_tooltips( true )
, border_size( BorderNormal )
, cached_border_size( BordersCount ) // invalid
, move_resize_maximized_windows( true )
, opMaxButtonRightClick( MaximizeOp )
, opMaxButtonMiddleClick( VMaximizeOp )
, opMaxButtonLeftClick( HMaximizeOp )
{ {
for(int i=0; i < NUM_COLORS*2; ++i) for(int i=0; i < NUM_COLORS*2; ++i)
pal[i] = NULL; pal[i] = NULL;
@ -50,21 +60,7 @@ KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
} }
} }
void KDecorationOptionsPrivate::defaultKWinSettings() unsigned long KDecorationOptionsPrivate::updateSettings( KConfig* config )
{
title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft();
title_buttons_right = KDecorationOptions::defaultTitleButtonsRight();
custom_button_positions = false;
show_tooltips = true;
border_size = BorderNormal;
cached_border_size = BordersCount; // invalid
move_resize_maximized_windows = true;
OpMaxButtonRightClick = MaximizeOp;
OpMaxButtonMiddleClick = VMaximizeOp;
OpMaxButtonLeftClick = HMaximizeOp;
}
unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
{ {
unsigned long changed = 0; unsigned long changed = 0;
KConfigGroup wmConfig(config, "WM"); KConfigGroup wmConfig(config, "WM");

View file

@ -34,13 +34,12 @@ DEALINGS IN THE SOFTWARE.
class KConfig; class KConfig;
class KWIN_EXPORT KDecorationOptionsPrivate : public KDecorationDefines class KDecorationOptionsPrivate : public KDecorationDefines
{ {
public: public:
KDecorationOptionsPrivate(); KDecorationOptionsPrivate();
virtual ~KDecorationOptionsPrivate(); ~KDecorationOptionsPrivate();
void defaultKWinSettings(); // shared implementation unsigned long updateSettings( KConfig* ); // shared implementation
unsigned long updateKWinSettings( KConfig* ); // shared implementation
BorderSize findPreferredBorderSize( BorderSize size, QList< BorderSize > ) const; // shared implementation BorderSize findPreferredBorderSize( BorderSize size, QList< BorderSize > ) const; // shared implementation
QColor colors[NUM_COLORS*2]; QColor colors[NUM_COLORS*2];
@ -52,9 +51,9 @@ class KWIN_EXPORT KDecorationOptionsPrivate : public KDecorationDefines
bool show_tooltips; bool show_tooltips;
BorderSize border_size, cached_border_size; BorderSize border_size, cached_border_size;
bool move_resize_maximized_windows; bool move_resize_maximized_windows;
WindowOperation OpMaxButtonRightClick; WindowOperation opMaxButtonRightClick;
WindowOperation OpMaxButtonMiddleClick; WindowOperation opMaxButtonMiddleClick;
WindowOperation OpMaxButtonLeftClick; WindowOperation opMaxButtonLeftClick;
}; };
#endif #endif

View file

@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE.
// This header file is internal. I mean it. // This header file is internal. I mean it.
// //
// This private header is used by KWin core.
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <ksharedconfig.h> #include <ksharedconfig.h>

View file

@ -46,21 +46,18 @@ Options::Options()
: electric_borders( 0 ), : electric_borders( 0 ),
electric_border_delay(0) electric_border_delay(0)
{ {
d = new KDecorationOptionsPrivate;
d->defaultKWinSettings();
updateSettings(); updateSettings();
} }
Options::~Options() Options::~Options()
{ {
delete d;
} }
unsigned long Options::updateSettings() unsigned long Options::updateSettings()
{ {
KSharedConfig::Ptr _config = KGlobal::config(); KSharedConfig::Ptr _config = KGlobal::config();
unsigned long changed = 0; unsigned long changed = 0;
changed |= d->updateKWinSettings( _config.data() ); // read decoration settings changed |= KDecorationOptions::updateSettings( _config.data() ); // read decoration settings
KConfigGroup config(_config, "Windows"); KConfigGroup config(_config, "Windows");
moveMode = stringToMoveResizeMode( config.readEntry("MoveMode", "Opaque" )); moveMode = stringToMoveResizeMode( config.readEntry("MoveMode", "Opaque" ));
@ -145,9 +142,9 @@ unsigned long Options::updateSettings()
electric_border_delay = config.readEntry("ElectricBorderDelay", 150); electric_border_delay = config.readEntry("ElectricBorderDelay", 150);
OpTitlebarDblClick = windowOperation( config.readEntry("TitlebarDoubleClickCommand", "Shade"), true ); OpTitlebarDblClick = windowOperation( config.readEntry("TitlebarDoubleClickCommand", "Shade"), true );
d->OpMaxButtonLeftClick = windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ); setOpMaxButtonLeftClick( windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ));
d->OpMaxButtonMiddleClick = windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ); setOpMaxButtonMiddleClick( windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ));
d->OpMaxButtonRightClick = windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ); setOpMaxButtonRightClick( windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ));
ignorePositionClasses = config.readEntry("IgnorePositionClasses",QStringList()); ignorePositionClasses = config.readEntry("IgnorePositionClasses",QStringList());
ignoreFocusStealingClasses = config.readEntry("IgnoreFocusStealingClasses",QStringList()); ignoreFocusStealingClasses = config.readEntry("IgnoreFocusStealingClasses",QStringList());

View file

@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject> #include <QObject>
#include <QFont> #include <QFont>
#include <QPalette> #include <QPalette>
#include <kdecoration_p.h> #include <kdecoration.h>
#include "placement.h" #include "placement.h"
#include "utils.h" #include "utils.h"

View file

@ -384,21 +384,19 @@ void KDecorationPreviewBridge::grabXServer( bool )
KDecorationPreviewOptions::KDecorationPreviewOptions() KDecorationPreviewOptions::KDecorationPreviewOptions()
{ {
d = new KDecorationOptionsPrivate; defaultKWinSettings();
d->defaultKWinSettings();
updateSettings(); updateSettings();
} }
KDecorationPreviewOptions::~KDecorationPreviewOptions() KDecorationPreviewOptions::~KDecorationPreviewOptions()
{ {
delete d;
} }
unsigned long KDecorationPreviewOptions::updateSettings() unsigned long KDecorationPreviewOptions::updateSettings()
{ {
KConfig cfg( "kwinrc", true ); KConfig cfg( "kwinrc", true );
unsigned long changed = 0; unsigned long changed = 0;
changed |= d->updateKWinSettings( &cfg ); changed |= KDecorationOptions::updateKWinSettings( &cfg );
return changed; return changed;
} }

View file

@ -21,7 +21,7 @@
#define KWINDECORATION_PREVIEW_H #define KWINDECORATION_PREVIEW_H
#include <QWidget> #include <QWidget>
#include <kdecoration_p.h> #include <kdecoration.h>
#include <kdecoration_plugins_p.h> #include <kdecoration_plugins_p.h>