mass whitespace cleanup

svn path=/trunk/KDE/kdebase/workspace/; revision=1021371
This commit is contained in:
Matthew Woehlke 2009-09-09 00:55:55 +00:00
parent 298dc3051a
commit af15bebbdd
31 changed files with 1388 additions and 1388 deletions

View file

@ -1,6 +1,6 @@
########### add version number into compilation defines
add_definitions ( -DAPP_VERSION=\\\"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\\\")
add_subdirectory( config )
add_subdirectory( config )
########### next target ###############
set(kwin_nitrogen_SRCS
@ -12,16 +12,16 @@ set(kwin_nitrogen_SRCS
nitrogenconfiguration.cpp
nitrogenexception.cpp
nitrogenexceptionlist.cpp
nitrogensizegrip.cpp
nitrogensizegrip.cpp
x11util.cpp
)
kde4_add_plugin(kwin3_nitrogen ${kwin_nitrogen_SRCS})
target_link_libraries(
kwin3_nitrogen
${KDE4_KDEUI_LIBS}
${X11_X11_LIB}
${X11_Xrender_LIB}
target_link_libraries(
kwin3_nitrogen
${KDE4_KDEUI_LIBS}
${X11_X11_LIB}
${X11_Xrender_LIB}
kdecorations
)

View file

@ -1,13 +1,13 @@
include_directories( ${KDEBASE_WORKSPACE_SOURCE_DIR}/kwin/lib )
set(kwin_nitrogen_config_PART_SRCS
config.cpp
set(kwin_nitrogen_config_PART_SRCS
config.cpp
itemmodel.cpp
../nitrogenconfiguration.cpp
../nitrogenexception.cpp
../nitrogenexceptionlist.cpp
nitrogenconfigurationui.cpp
nitrogenconfigurationui.cpp
nitrogenexceptiondialog.cpp
nitrogenexceptionlistwidget.cpp
nitrogenexceptionmodel.cpp
@ -16,7 +16,7 @@ set(kwin_nitrogen_config_PART_SRCS
kde4_add_plugin(kwin_nitrogen_config ${kwin_nitrogen_config_PART_SRCS})
target_link_libraries(
kwin_nitrogen_config
kwin_nitrogen_config
${KDE4_KDEUI_LIBS}
${QT_QTGUI_LIBRARY}
)

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// config.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright (C) 2008 Lubos Lunak <l.lunak@kde.org>
//
@ -24,7 +24,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KAboutData>
@ -46,128 +46,128 @@ extern "C"
{ return ( new Nitrogen::Config( conf, parent ) ); }
}
namespace Nitrogen
namespace Nitrogen
{
//_______________________________________________________________________
Config::Config( KConfig*, QWidget* parent ): QObject( parent )
{
KGlobal::locale()->insertCatalog("kwin_clients");
configuration_ = new KConfig( "nitrogenrc" );
KConfigGroup configurationGroup( configuration_, "Windeco");
user_interface_ = new NitrogenConfigurationUI( parent );
user_interface_ = new NitrogenConfigurationUI( parent );
connect( user_interface_->titleAlignment, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
connect( user_interface_->buttonSize, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
connect( user_interface_->frameBorder, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
connect( user_interface_->blendColor, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
connect( user_interface_->sizeGripMode, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
connect( user_interface_->drawSeparator, SIGNAL(clicked()), SIGNAL(changed()) );
connect( user_interface_->titleOutline, SIGNAL(clicked()), SIGNAL(changed()) );
connect( user_interface_->useOxygenShadows, SIGNAL(clicked()), SIGNAL(changed()) );
connect( user_interface_->exceptions, SIGNAL(changed()), SIGNAL(changed()) );
load( configurationGroup );
user_interface_->show();
}
//_______________________________________________________________________
Config::~Config()
{
delete user_interface_;
delete configuration_;
}
//_______________________________________________________________________
void Config::load( const KConfigGroup& )
{
// load standard configuration
KConfigGroup configurationGroup( configuration_, "Windeco");
loadConfiguration( NitrogenConfiguration( configurationGroup ) );
// load exceptions
NitrogenExceptionList exceptions;
exceptions.read( *configuration_ );
if( exceptions.empty() )
{ exceptions = NitrogenExceptionList::defaultList(); }
// install in ui
user_interface_->exceptions->setExceptions( exceptions );
}
//_______________________________________________________________________
void Config::save( KConfigGroup& )
{
// save standard configuration
KConfigGroup configurationGroup( configuration_, "Windeco");
// when writting text entries, on needs to make sure that strings written
// when writting text entries, on needs to make sure that strings written
// to the configuration file are *not* translated using current locale
configurationGroup.writeEntry(
NitrogenConfig::TITLE_ALIGNMENT,
configurationGroup.writeEntry(
NitrogenConfig::TITLE_ALIGNMENT,
NitrogenConfiguration::titleAlignmentName( NitrogenConfiguration::titleAlignment( user_interface_->titleAlignment->currentText(), true ), false ) );
configurationGroup.writeEntry(
NitrogenConfig::BUTTON_SIZE,
configurationGroup.writeEntry(
NitrogenConfig::BUTTON_SIZE,
NitrogenConfiguration::buttonSizeName( NitrogenConfiguration::buttonSize( user_interface_->buttonSize->currentText(), true ), false ) );
configurationGroup.writeEntry(
NitrogenConfig::BLEND_COLOR,
configurationGroup.writeEntry(
NitrogenConfig::BLEND_COLOR,
NitrogenConfiguration::blendColorName( NitrogenConfiguration::blendColor( user_interface_->blendColor->currentText(), true ), false ) );
configurationGroup.writeEntry(
NitrogenConfig::FRAME_BORDER,
configurationGroup.writeEntry(
NitrogenConfig::FRAME_BORDER,
NitrogenConfiguration::frameBorderName( NitrogenConfiguration::frameBorder( user_interface_->frameBorder->currentText(), true ), false ) );
configurationGroup.writeEntry(
configurationGroup.writeEntry(
NitrogenConfig::SIZE_GRIP_MODE,
NitrogenConfiguration::sizeGripModeName( NitrogenConfiguration::sizeGripMode( user_interface_->sizeGripMode->currentText(), true ), false ) );
configurationGroup.writeEntry( NitrogenConfig::DRAW_SEPARATOR, user_interface_->drawSeparator->isChecked() );
configurationGroup.writeEntry( NitrogenConfig::DRAW_TITLE_OUTLINE, user_interface_->titleOutline->isChecked() );
configurationGroup.writeEntry( NitrogenConfig::USE_OXYGEN_SHADOWS, user_interface_->useOxygenShadows->isChecked() );
// write exceptions
user_interface_->exceptions->exceptions().write( *configuration_ );
user_interface_->exceptions->exceptions().write( *configuration_ );
// sync configuration
configuration_->sync();
}
//_______________________________________________________________________
void Config::defaults()
{
// install default configuration
loadConfiguration( NitrogenConfiguration() );
// install default exceptions
user_interface_->exceptions->setExceptions( NitrogenExceptionList::defaultList() );
// emit changed signal
emit changed();
}
//_______________________________________________________________________
void Config::loadConfiguration( const NitrogenConfiguration& configuration )
{
user_interface_->titleAlignment->setCurrentIndex( user_interface_->titleAlignment->findText( configuration.titleAlignmentName( true ) ) );
user_interface_->buttonSize->setCurrentIndex( user_interface_->buttonSize->findText( configuration.buttonSizeName( true ) ) );
user_interface_->titleAlignment->setCurrentIndex( user_interface_->titleAlignment->findText( configuration.titleAlignmentName( true ) ) );
user_interface_->buttonSize->setCurrentIndex( user_interface_->buttonSize->findText( configuration.buttonSizeName( true ) ) );
user_interface_->blendColor->setCurrentIndex( user_interface_->blendColor->findText( configuration.blendColorName( true ) ) );
user_interface_->frameBorder->setCurrentIndex( user_interface_->frameBorder->findText( configuration.frameBorderName( true ) ) );
user_interface_->sizeGripMode->setCurrentIndex( user_interface_->sizeGripMode->findText( configuration.sizeGripModeName( true ) ) );
@ -176,8 +176,8 @@ namespace Nitrogen
user_interface_->titleOutline->setChecked( configuration.drawTitleOutline() );
user_interface_->useOxygenShadows->setChecked( configuration.useOxygenShadows() );
}
//_______________________________________________________________________
void Config::aboutNitrogen( void )
{
@ -187,18 +187,18 @@ namespace Nitrogen
KLocalizedString(),
KLocalizedString(),
( "http://www.kde-look.org/content/show.php/Nitrogen?content=99551" ) );
aboutData.addAuthor(
aboutData.addAuthor(
ki18n( "Hugo Pereira Da Costa" ), ki18n( "Developer" ),
"hugo.pereira@free.fr",
"http://hugo.pereira.free.fr/index.php" );
aboutData.addCredit( ki18n( "Oxygen team" ) );
// create dialog
KAboutApplicationDialog( &aboutData, 0 ).exec();
}
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// config.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright (C) 2008 Lubos Lunak <l.lunak@kde.org>
//
@ -27,7 +27,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KConfig>
@ -38,55 +38,55 @@
namespace Nitrogen {
class NitrogenConfiguration;
// nitrogen configuration object
class Config: public QObject
{
Q_OBJECT
public:
//! constructor
Config( KConfig* conf, QWidget* parent );
//! destructor
~Config();
signals:
//! emmited whenever configuration is changed
void changed();
public slots:
//! load configuration
void load( const KConfigGroup& conf );
//! save configuration
void save( KConfigGroup& conf );
//! restore defaults
void defaults();
private slots:
//! about nitrogen
void aboutNitrogen( void );
private:
//! load configuration
void loadConfiguration( const NitrogenConfiguration& );
//! user interface
NitrogenConfigurationUI *user_interface_;
//! kconfiguration object
KConfig *configuration_;
};
} //namespace Nitrogen
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// itemmodel.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
/*!
@ -44,32 +44,32 @@ ItemModel::ItemModel( QObject* parent ):
//____________________________________________________________
void ItemModel::sort( int column, Qt::SortOrder order )
{
{
// store column and order
sort_column_ = column;
sort_order_ = order;
// emit signals and call private methods
emit layoutAboutToBeChanged();
_sort( column, order );
emit layoutChanged();
}
//____________________________________________________________
QModelIndexList ItemModel::indexes( int column, const QModelIndex& parent ) const
{
{
QModelIndexList out;
int rows( rowCount( parent ) );
for( int row = 0; row < rows; row++ )
{
{
QModelIndex index( this->index( row, column, parent ) );
if( !index.isValid() ) continue;
out.push_back( index );
out += indexes( column, index );
}
return out;
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// itemmodel.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
/*!
\file ItemModel.h
@ -38,78 +38,78 @@
//! Job model. Stores job information for display in lists
class ItemModel : public QAbstractItemModel
{
public:
//! constructor
ItemModel(QObject *parent = 0);
//! destructor
virtual ~ItemModel()
{}
//! return all indexes in model starting from parent [recursive]
QModelIndexList indexes( int column = 0, const QModelIndex& parent = QModelIndex() ) const;
//!@name sorting
//@{
//! sort
virtual void sort( void )
{ sort( sortColumn(), sortOrder() ); }
//! sort
virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
//! current sorting column
const int& sortColumn( void ) const
{ return sort_column_; }
//! current sort order
const Qt::SortOrder& sortOrder( void ) const
{ return sort_order_; }
//@}
protected:
//! this sort columns without calling the layout changed callbacks
void _sort( void )
{ _sort( sortColumn(), sortOrder() ); }
//! private sort, with no signals emmitted
virtual void _sort( int column, Qt::SortOrder order ) = 0;
//! used to sort items in list
class SortFTor
{
public:
//! constructor
SortFTor( const int& type, Qt::SortOrder order = Qt::AscendingOrder ):
type_( type ),
order_( order )
{}
protected:
//! column
int type_;
//! order
Qt::SortOrder order_;
};
private:
private:
//! sorting column
int sort_column_;
//! sorting order
Qt::SortOrder sort_order_;
};
#endif

View file

@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
// listmodel.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,7 +22,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <algorithm>
@ -35,12 +35,12 @@
//! Job model. Stores job information for display in lists
template<class T> class ListModel : public ItemModel
{
public:
//! value type
typedef T ValueType;
//! reference
typedef T& Reference;
@ -49,7 +49,7 @@ template<class T> class ListModel : public ItemModel
//! list of vector
typedef std::vector<ValueType> List;
//! list of vector
typedef std::set<ValueType> Set;
@ -57,217 +57,217 @@ template<class T> class ListModel : public ItemModel
ListModel(QObject *parent = 0):
ItemModel( parent )
{}
//! destructor
virtual ~ListModel()
{}
//!@name methods reimplemented from base class
//@{
//! flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
{
if (!index.isValid()) return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
//! unique index for given row, column and parent index
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
{
// check if index is valid
if( !hasIndex( row, column, parent ) ) return QModelIndex();
// return invalid index if parent is valid
if( parent.isValid() ) return QModelIndex();
// check against values_
// check against values_
return ( row < (int) values_.size() ) ? createIndex( row, column ):QModelIndex();
}
//! index of parent
virtual QModelIndex parent(const QModelIndex &) const
{ return QModelIndex(); }
//! number of rows below given index
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const
{ return parent.isValid() ? 0:values_.size(); }
{ return parent.isValid() ? 0:values_.size(); }
//@}
//!@name selection
//@{
//! clear internal list selected items
virtual void clearSelectedIndexes( void )
{ selection_.clear(); }
//! store index internal selection state
virtual void setIndexSelected( const QModelIndex& index, bool value )
{
if( value ) selection_.push_back( get(index) );
{
if( value ) selection_.push_back( get(index) );
else selection_.erase( std::remove( selection_.begin(), selection_.end(), get(index) ), selection_.end() );
}
}
//! get list of internal selected items
virtual QModelIndexList selectedIndexes( void ) const
{
QModelIndexList out;
QModelIndexList out;
for( typename List::const_iterator iter = selection_.begin(); iter != selection_.end(); iter++ )
{
{
QModelIndex index( ListModel::index( *iter ) );
if( index.isValid() ) out.push_back( index );
if( index.isValid() ) out.push_back( index );
}
return out;
}
//@}
//!@name interface
//@{
//! add value
virtual void add( const ValueType& value )
{
emit layoutAboutToBeChanged();
{
emit layoutAboutToBeChanged();
_add( value );
_sort();
emit layoutChanged();
}
//! add values
virtual void add( const List& values )
{
{
// check if not empty
// this avoids sending useless signals
if( values.empty() ) return;
emit layoutAboutToBeChanged();
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
emit layoutAboutToBeChanged();
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
{ _add( *iter ); }
_sort();
emit layoutChanged();
}
//! add values
/*! this method uses a Set to add the values. It speeds up the updating of existing values */
virtual void add( Set values )
{
emit layoutAboutToBeChanged();
for( typename List::iterator iter = values_.begin(); iter != values_.end(); iter++ )
{
{
emit layoutAboutToBeChanged();
for( typename List::iterator iter = values_.begin(); iter != values_.end(); iter++ )
{
// see if current iterator is found in values set
typename Set::iterator found_iter( values.find( *iter ) );
if( found_iter != values.end() )
if( found_iter != values.end() )
{
*iter = *found_iter;
values.erase( found_iter );
}
}
// insert remaining values at the end
values_.insert( values_.end(), values.begin(), values.end() );
_sort();
emit layoutChanged();
}
//! insert values
virtual void insert( const QModelIndex& index, const ValueType& value )
{
emit layoutAboutToBeChanged();
emit layoutAboutToBeChanged();
_insert( index, value );
emit layoutChanged();
}
//! insert values
virtual void insert( const QModelIndex& index, const List& values )
{
emit layoutAboutToBeChanged();
emit layoutAboutToBeChanged();
// need to loop in reverse order so that the "values" ordering is preserved
for( typename List::const_reverse_iterator iter = values.rbegin(); iter != values.rend(); iter++ )
for( typename List::const_reverse_iterator iter = values.rbegin(); iter != values.rend(); iter++ )
_insert( index, *iter );
emit layoutChanged();
}
//! insert values
virtual void replace( const QModelIndex& index, const ValueType& value )
{
if( !index.isValid() ) add( value );
else {
emit layoutAboutToBeChanged();
emit layoutAboutToBeChanged();
setIndexSelected( index, false );
values_[index.row()] = value;
setIndexSelected( index, true );
emit layoutChanged();
}
}
//! remove
virtual void remove( const ValueType& value )
{
{
emit layoutAboutToBeChanged();
_remove( value );
emit layoutChanged();
return;
}
//! remove
virtual void remove( const List& values )
{
{
// check if not empty
// this avoids sending useless signals
if( values.empty() ) return;
emit layoutAboutToBeChanged();
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
{ _remove( *iter ); }
emit layoutChanged();
return;
}
//! clear
virtual void clear( void )
{ set( List() ); }
//! update values from list
/*!
values that are not found in current are removed
/*!
values that are not found in current are removed
new values are set to the end.
This is slower than the "set" method, but the selection is not cleared in the process
*/
virtual void update( List values )
{
emit layoutAboutToBeChanged();
// store values to be removed
List removed_values;
// update values that are common to both lists
for( typename List::iterator iter = values_.begin(); iter != values_.end(); iter++ )
{
// see if iterator is in list
typename List::iterator found_iter( std::find( values.begin(), values.end(), *iter ) );
if( found_iter == values.end() ) removed_values.push_back( *iter );
@ -275,83 +275,83 @@ template<class T> class ListModel : public ItemModel
*iter = *found_iter;
values.erase( found_iter );
}
}
// remove values that have not been found in new list
for( typename List::const_iterator iter = removed_values.begin(); iter != removed_values.end(); iter++ )
for( typename List::const_iterator iter = removed_values.begin(); iter != removed_values.end(); iter++ )
{ _remove( *iter ); }
// add remaining values
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
{ _add( *iter ); }
_sort();
emit layoutChanged();
}
//! set all values
virtual void set( const List& values )
{
{
emit layoutAboutToBeChanged();
values_ = values;
selection_.clear();
_sort();
emit layoutChanged();
return;
}
//! return all values
const List& get( void ) const
{ return values_; }
//! return value for given index
virtual ValueType get( const QModelIndex& index ) const
{ return (index.isValid() && index.row() < int(values_.size()) ) ? values_[index.row()]:ValueType(); }
//! return value for given index
virtual ValueType& get( const QModelIndex& index )
{
{
assert( index.isValid() && index.row() < int( values_.size() ) );
return values_[index.row()];
return values_[index.row()];
}
//! return all values
List get( const QModelIndexList& indexes ) const
{
{
List out;
for( QModelIndexList::const_iterator iter = indexes.begin(); iter != indexes.end(); iter++ )
{ if( iter->isValid() && iter->row() < int(values_.size()) ) out.push_back( get( *iter ) ); }
return out;
}
//! return index associated to a given value
virtual QModelIndex index( const ValueType& value, int column = 0 ) const
{
{
for( unsigned int row=0; row<values_.size(); row++ )
{ if( value == values_[row] ) return index( row, column ); }
return QModelIndex();
}
//@}
protected:
//! return all values
List& _get( void )
{ return values_; }
//! add, without update
virtual void _add( const ValueType& value )
{
typename List::iterator iter = std::find( values_.begin(), values_.end(), value );
if( iter == values_.end() ) values_.push_back( value );
if( iter == values_.end() ) values_.push_back( value );
else *iter = value;
}
//! add, without update
virtual void _insert( const QModelIndex& index, const ValueType& value )
{
@ -361,22 +361,22 @@ template<class T> class ListModel : public ItemModel
for( ;iter != values_.end() && row != index.row(); iter++, row++ ){}
values_.insert( iter, value );
}
//! remove, without update
virtual void _remove( const ValueType& value )
{
values_.erase( std::remove( values_.begin(), values_.end(), value ), values_.end() );
selection_.erase( std::remove( selection_.begin(), selection_.end(), value ), selection_.end() );
}
private:
//! values
List values_;
//! selection
List selection_;
};
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenconfigurationui.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <kdeversion.h>
@ -36,7 +36,7 @@
namespace Nitrogen
{
//_________________________________________________________
NitrogenConfigurationUI::NitrogenConfigurationUI( QWidget* parent ):
QWidget( parent ),
@ -48,37 +48,37 @@ namespace Nitrogen
drawSeparator(0),
titleOutline(0)
{ setupUI(); }
//_________________________________________________________
void NitrogenConfigurationUI::setupUI( void )
{
QVBoxLayout* mainLayout = new QVBoxLayout( this );
mainLayout->setSpacing(6);
mainLayout->setMargin(0);
// tab widget for basic and advanced mode
QTabWidget* tab( new QTabWidget( this ) );
mainLayout->addWidget( tab );
// basic configuration
{
QWidget *basicWidget = new QWidget();
int index = tab->addTab( basicWidget, i18n("&General") );
tab->setTabToolTip( index, i18n( "Basic window decoration configuration options" ) );
QVBoxLayout* vboxLayout = new QVBoxLayout();
vboxLayout->setMargin( 6 );
vboxLayout->setSpacing( 6 );
basicWidget->setLayout( vboxLayout );
QGridLayout* gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setMargin(0);
vboxLayout->addLayout( gridLayout );
gridLayout->setColumnStretch(2, 1);
// frame border
QLabel* label;
gridLayout->addWidget( label = new QLabel( i18n("Border size:"), basicWidget ), 0, 0, 1, 1);
@ -94,60 +94,60 @@ namespace Nitrogen
<< NitrogenConfiguration::frameBorderName( NitrogenConfiguration::BorderVeryHuge, true )
<< NitrogenConfiguration::frameBorderName( NitrogenConfiguration::BorderOversized, true )
);
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
label->setBuddy( frameBorder );
// title alignment
gridLayout->addWidget( label = new QLabel( i18n("Title alignment:"), basicWidget ), 1, 0, 1, 1 );
gridLayout->addWidget( titleAlignment = new QComboBox(basicWidget), 1, 1, 1, 1 );
titleAlignment->setObjectName(QString::fromUtf8("titleAlignment"));
titleAlignment->setObjectName(QString::fromUtf8("titleAlignment"));
titleAlignment->insertItems(0, QStringList()
<< NitrogenConfiguration::titleAlignmentName( Qt::AlignLeft, true )
<< NitrogenConfiguration::titleAlignmentName( Qt::AlignHCenter, true )
<< NitrogenConfiguration::titleAlignmentName( Qt::AlignRight, true )
);
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
label->setBuddy( titleAlignment );
// button size
gridLayout->addWidget( label = new QLabel( i18n("Button size:"), basicWidget ), 2, 0, 1, 1 );
gridLayout->addWidget( buttonSize = new QComboBox(basicWidget), 2, 1, 1, 1 );
buttonSize->setObjectName(QString::fromUtf8("buttonSize"));
buttonSize->setObjectName(QString::fromUtf8("buttonSize"));
buttonSize->insertItems(0, QStringList()
<< NitrogenConfiguration::buttonSizeName( NitrogenConfiguration::ButtonSmall, true )
<< NitrogenConfiguration::buttonSizeName( NitrogenConfiguration::ButtonDefault, true )
<< NitrogenConfiguration::buttonSizeName( NitrogenConfiguration::ButtonLarge, true )
<< NitrogenConfiguration::buttonSizeName( NitrogenConfiguration::ButtonHuge, true )
);
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
label->setBuddy( buttonSize );
vboxLayout->addStretch(1);
}
// advanced configuration
{
QWidget *advancedWidget = new QWidget();
int index = tab->addTab( advancedWidget, "&Advanced" );
tab->setTabToolTip( index, i18n( "Advanced window decoration configuration options" ) );
QVBoxLayout* vboxLayout = new QVBoxLayout();
vboxLayout->setMargin( 6 );
vboxLayout->setSpacing( 6 );
advancedWidget->setLayout( vboxLayout );
QGridLayout* gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setMargin(0);
vboxLayout->addLayout( gridLayout );
gridLayout->setColumnStretch(2, 1);
// title bar blending
QLabel* label;
gridLayout->addWidget( label = new QLabel( i18n("Background style:" ), advancedWidget ), 1, 0, 1, 1 );
@ -157,10 +157,10 @@ namespace Nitrogen
<< NitrogenConfiguration::blendColorName( NitrogenConfiguration::NoBlending, true )
<< NitrogenConfiguration::blendColorName( NitrogenConfiguration::RadialBlending, true )
);
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
label->setBuddy( blendColor );
// draw size grip
gridLayout->addWidget( label = new QLabel( i18n("Extra Size grip display:"), advancedWidget ), 2, 0, 1, 1 );
gridLayout->addWidget( sizeGripMode = new QComboBox(advancedWidget), 2, 1, 1, 1 );
@ -173,22 +173,22 @@ namespace Nitrogen
<< NitrogenConfiguration::sizeGripModeName( NitrogenConfiguration::SizeGripNever, true )
<< NitrogenConfiguration::sizeGripModeName( NitrogenConfiguration::SizeGripWhenNeeded, true )
);
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
label->setBuddy( sizeGripMode );
// active window title outline
vboxLayout->addWidget( titleOutline = new QCheckBox( i18n("Outline active window title"), advancedWidget) );
titleOutline->setObjectName(QString::fromUtf8("titleOutline"));
titleOutline->setWhatsThis(i18n(
"When enabled, an additional frame is shown around the active window as well as its title"));
// draw separator
vboxLayout->addWidget( drawSeparator = new QCheckBox( i18n("Draw separator between title bar and active window contents"), advancedWidget ) );
drawSeparator->setObjectName(QString::fromUtf8("drawSeparator"));
drawSeparator->setWhatsThis(i18n(
"When enabled, this option makes an horizontal separator appear between the window title bar and the window contents."));
// oxygen shadow
vboxLayout->addWidget( useOxygenShadows = new QCheckBox( i18n("Glow active window" ), advancedWidget ) );
useOxygenShadows->setObjectName(QString::fromUtf8("useOxygenShadows"));
@ -196,9 +196,9 @@ namespace Nitrogen
"When this option is enabled, oxygen signature blue glow is used for the active window shadow."));
connect( titleOutline, SIGNAL(toggled( bool )), drawSeparator, SLOT( setDisabled( bool ) ) );
}
// exceptions
{
exceptions = new NitrogenExceptionListWidget();
@ -206,9 +206,9 @@ namespace Nitrogen
int index = tab->addTab( exceptions, "&Window-Specific" );
tab->setTabToolTip( index, i18n( "Configure window specific decoration options, based on window name" ) );
}
QMetaObject::connectSlotsByName(this);
QMetaObject::connectSlotsByName(this);
}
}

View file

@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenconfigurationui.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,7 +22,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <kdeversion.h>
@ -39,17 +39,17 @@ namespace Nitrogen
//_____________________________________________
class NitrogenConfigurationUI: public QWidget
{
Q_OBJECT
public:
//! constructor
NitrogenConfigurationUI( QWidget* );
//! setup ui
void setupUI( void );
//! title alignment
QComboBox *titleAlignment;
@ -64,22 +64,22 @@ namespace Nitrogen
//! size grip
QComboBox *sizeGripMode;
//! draw separator
QCheckBox *drawSeparator;
//! active window title outline
QCheckBox *titleOutline;
//! nitrogen shadow
QCheckBox *useOxygenShadows;
//! about nitrogen
QPushButton *aboutNitrogen;
NitrogenExceptionListWidget *exceptions;
NitrogenExceptionListWidget *exceptions;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptiondialog.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QGroupBox>
@ -32,12 +32,12 @@
namespace Nitrogen
{
//___________________________________________
NitrogenExceptionDialog::NitrogenExceptionDialog( QWidget* parent ):
KDialog( parent )
{
// define buttons
setButtons( Ok|Cancel );
showButtonSeparator( true );
@ -49,18 +49,18 @@ namespace Nitrogen
widget->setLayout( new QVBoxLayout() );
widget->layout()->setSpacing(5);
widget->layout()->setMargin(0);
// exception definition
QGroupBox* box;
widget->layout()->addWidget( box = new QGroupBox( i18n( "Definition" ), widget ) );
QGridLayout* gridLayout = new QGridLayout();
gridLayout->setSpacing(5);
gridLayout->setMargin(5);
box->setLayout( gridLayout );
QLabel *label;
// exception type
gridLayout->addWidget( label = new QLabel( i18n( "Exception type: " ), box ), 0, 0, 1, 1 );
gridLayout->addWidget( exceptionType = new QComboBox(box), 0, 1, 1, 1 );
@ -70,9 +70,9 @@ namespace Nitrogen
exceptionType->setToolTip( i18n(
"Select here the window characteristic used to \n"
"identify windows to which the exception apply." ) );
label->setAlignment( Qt::AlignRight );
// regular expression
gridLayout->addWidget( label = new QLabel( i18n( "Regular expression to match: " ), box ), 1, 0, 1, 1 );
gridLayout->addWidget( exceptionEditor = new KLineEdit( box ), 1, 1, 1, 1 );
@ -82,16 +82,16 @@ namespace Nitrogen
"identify windows to which the exception apply." ) );
label->setAlignment( Qt::AlignRight );
// decoration flags
widget->layout()->addWidget( box = new QGroupBox( i18n( "Decoration" ), widget ) );
widget->layout()->addWidget( box = new QGroupBox( i18n( "Decoration" ), widget ) );
gridLayout = new QGridLayout();
gridLayout->setSpacing(5);
gridLayout->setMargin(5);
box->setLayout( gridLayout );
QCheckBox* checkbox;
// border size
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Border size:" ), box ), 0, 0, 1, 1 );
gridLayout->addWidget( frameBorder = new QComboBox(box), 0, 1, 1, 1 );
@ -109,7 +109,7 @@ namespace Nitrogen
checkboxes_.insert( std::make_pair( NitrogenException::FrameBorder, checkbox ) );
checkbox->setToolTip( i18n("If checked, specified frame border is used in place of default value.") );
connect( checkbox, SIGNAL( toggled( bool ) ), frameBorder, SLOT( setEnabled( bool ) ) );
// blend color
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Background style:" ), box ), 1, 0, 1, 1 );
gridLayout->addWidget( blendColor = new QComboBox(box), 1, 1, 1, 1 );
@ -120,7 +120,7 @@ namespace Nitrogen
checkboxes_.insert( std::make_pair( NitrogenException::BlendColor, checkbox ) );
checkbox->setToolTip( i18n("If checked, specified blending color is used in title bar in place of default value.") );
connect( checkbox, SIGNAL( toggled( bool ) ), blendColor, SLOT( setEnabled( bool ) ) );
// size grip
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Size grip display:" ), box ), 2, 0, 1, 1 );
gridLayout->addWidget( sizeGripMode = new QComboBox( box ), 2, 1, 1, 1 );
@ -145,63 +145,63 @@ namespace Nitrogen
drawSeparator->setEnabled( false );
checkboxes_.insert( std::make_pair( NitrogenException::DrawSeparator, checkbox ) );
connect( checkbox, SIGNAL( toggled( bool ) ), drawSeparator, SLOT( setEnabled( bool ) ) );
}
//___________________________________________
void NitrogenExceptionDialog::setException( NitrogenException exception )
{
// store exception internally
exception_ = exception;
// type
exceptionType->setCurrentIndex( exceptionType->findText( exception.typeName() ) );
// regular expression
exceptionEditor->setText( exception.regExp().pattern() );
// border size
frameBorder->setCurrentIndex( frameBorder->findText( exception.frameBorderName( true ) ) );
// blend color
blendColor->setCurrentIndex( blendColor->findText( exception.blendColorName( true ) ) );
// size grip
sizeGripMode->setCurrentIndex( sizeGripMode->findText( exception.sizeGripModeName( true ) ) );
// flags
drawSeparator->setValue( exception.drawSeparator() );
titleOutline->setValue( exception.drawTitleOutline() );
// mask
for( CheckBoxMap::iterator iter = checkboxes_.begin(); iter != checkboxes_.end(); iter++ )
{ iter->second->setChecked( exception.mask() & iter->first ); }
}
//___________________________________________
NitrogenException NitrogenExceptionDialog::exception( void ) const
{
{
NitrogenException exception( exception_ );
exception.setType( NitrogenException::type( exceptionType->currentText() ) );
exception.regExp().setPattern( exceptionEditor->text() );
exception.setFrameBorder( NitrogenException::frameBorder( frameBorder->currentText(), true ) );
exception.setBlendColor( NitrogenException::blendColor( blendColor->currentText(), true ) );
exception.setBlendColor( NitrogenException::blendColor( blendColor->currentText(), true ) );
exception.setSizeGripMode( NitrogenException::sizeGripMode( sizeGripMode->currentText(), true ) );
// flags
exception.setDrawSeparator( drawSeparator->isChecked() );
exception.setDrawTitleOutline( titleOutline->isChecked() );
// mask
unsigned int mask = NitrogenException::None;
for( CheckBoxMap::const_iterator iter = checkboxes_.begin(); iter != checkboxes_.end(); iter++ )
{ if( iter->second->isChecked() ) mask |= iter->first; }
exception.setMask( mask );
return exception;
}
//___________________________________________
@ -216,9 +216,9 @@ namespace Nitrogen
//___________________________________________
void NitrogenExceptionDialog::ComboBox::setValue( bool checked )
{ setCurrentIndex( findText( checked ? Yes:No ) ); }
//___________________________________________
bool NitrogenExceptionDialog::ComboBox::isChecked( void ) const
{ return currentText() == Yes; }
}

View file

@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptiondialog.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,7 +22,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KDialog>
@ -36,76 +36,76 @@
namespace Nitrogen
{
//! nitrogen exceptions list
class NitrogenExceptionDialog: public KDialog
{
public:
//! constructor
NitrogenExceptionDialog( QWidget* parent );
//! set exception
void setException( NitrogenException );
//! get exception
NitrogenException exception( void ) const;
private:
//! line editor
KLineEdit* exceptionEditor;
//! blend combobox
QComboBox* exceptionType;
//! border size
QComboBox* frameBorder;
//! blend combobox
QComboBox* blendColor;
//! size grip
QComboBox* sizeGripMode;
//! map mask and checkbox
typedef std::map< NitrogenException::AttributesMask, QCheckBox*> CheckBoxMap;
//! map mask and checkbox
CheckBoxMap checkboxes_;
//! internal exception
NitrogenException exception_;
//! local combobox to handle configuration checkboxes
class ComboBox: public QComboBox
{
public:
public:
static const QString Yes;
static const QString No;
//! constructor
ComboBox( QWidget* parent );
//! set value
void setValue( bool checked );
//! true if yes is checkd
bool isChecked( void ) const;
};
//! overwrite colors
ComboBox* titleOutline;
//! draw separator
ComboBox* drawSeparator;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// NitrogenExceptionListWidget.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QLayout>
@ -34,19 +34,19 @@
//__________________________________________________________
namespace Nitrogen
{
//__________________________________________________________
NitrogenExceptionListWidget::NitrogenExceptionListWidget( QWidget* parent, NitrogenConfiguration default_configuration ):
QWidget( parent ),
default_configuration_( default_configuration )
{
// layout
QHBoxLayout* h_layout = new QHBoxLayout();
h_layout->setMargin(6);
h_layout->setSpacing(6);
setLayout( h_layout );
// list
h_layout->addWidget( list_ = new QTreeView( this ) );
_list().setAllColumnsShowFocus( true );
@ -55,31 +55,31 @@ namespace Nitrogen
_list().setModel( &_model() );
_list().sortByColumn( NitrogenExceptionModel::TYPE );
_list().setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Ignored ) );
// button layout
QVBoxLayout* v_layout = new QVBoxLayout();
v_layout->setMargin(0);
v_layout->setSpacing(5);
h_layout->addLayout( v_layout );
KIconLoader* icon_loader = KIconLoader::global();
v_layout->addWidget( up_button_ = new KPushButton(
v_layout->addWidget( up_button_ = new KPushButton(
KIcon( "arrow-up", icon_loader ),
i18n("Move &Up"), this ) );
v_layout->addWidget( down_button_ = new KPushButton(
v_layout->addWidget( down_button_ = new KPushButton(
KIcon( "arrow-down", icon_loader ),
i18n("Move &Down"), this ) );
v_layout->addWidget( add_button_ = new KPushButton(
KIcon( "list-add", icon_loader ),
v_layout->addWidget( add_button_ = new KPushButton(
KIcon( "list-add", icon_loader ),
i18n("&Add"), this ) );
v_layout->addWidget( remove_button_ = new KPushButton(
KIcon( "list-remove", icon_loader ),
v_layout->addWidget( remove_button_ = new KPushButton(
KIcon( "list-remove", icon_loader ),
i18n("&Remove"), this ) );
v_layout->addWidget( edit_button_ = new KPushButton(
v_layout->addWidget( edit_button_ = new KPushButton(
KIcon( "edit-rename", icon_loader ),
i18n("&Edit"), this ) );
@ -90,66 +90,66 @@ namespace Nitrogen
connect( remove_button_, SIGNAL( clicked() ), SLOT( _remove() ) );
connect( up_button_, SIGNAL( clicked() ), SLOT( _up() ) );
connect( down_button_, SIGNAL( clicked() ), SLOT( _down() ) );
connect( &_list(), SIGNAL( activated( const QModelIndex& ) ), SLOT( _edit() ) );
connect( &_list(), SIGNAL( activated( const QModelIndex& ) ), SLOT( _edit() ) );
connect( &_list(), SIGNAL( clicked( const QModelIndex& ) ), SLOT( _toggle( const QModelIndex& ) ) );
connect( _list().selectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ), SLOT( _updateButtons() ) );
_updateButtons();
_resizeColumns();
}
//__________________________________________________________
void NitrogenExceptionListWidget::setExceptions( const NitrogenExceptionList& exceptions )
{
_model().set( NitrogenExceptionModel::List( exceptions.begin(), exceptions.end() ) );
{
_model().set( NitrogenExceptionModel::List( exceptions.begin(), exceptions.end() ) );
_resizeColumns();
}
//__________________________________________________________
NitrogenExceptionList NitrogenExceptionListWidget::exceptions( void ) const
{
{
NitrogenExceptionModel::List exceptions( _model().get() );
NitrogenExceptionList out;
for( NitrogenExceptionModel::List::const_iterator iter = exceptions.begin(); iter != exceptions.end(); iter++ )
{ out.push_back( *iter ); }
return out;
}
//__________________________________________________________
void NitrogenExceptionListWidget::_updateButtons( void )
{
bool has_selection( !_list().selectionModel()->selectedRows().empty() );
remove_button_->setEnabled( has_selection );
edit_button_->setEnabled( has_selection );
up_button_->setEnabled( has_selection && !_list().selectionModel()->isRowSelected( 0, QModelIndex() ) );
down_button_->setEnabled( has_selection && !_list().selectionModel()->isRowSelected( _model().rowCount()-1, QModelIndex() ) );
}
//_______________________________________________________
void NitrogenExceptionListWidget::_add( void )
{
// map dialog
NitrogenExceptionDialog dialog( this );
dialog.setException( default_configuration_ );
if( dialog.exec() == QDialog::Rejected ) return;
// retrieve exception and check
NitrogenException exception( dialog.exception() );
if( !_checkException( exception ) ) return;
// create new item
_model().add( exception );
// make sure item is selected
QModelIndex index( _model().index( exception ) );
if( index != _list().selectionModel()->currentIndex() )
@ -157,39 +157,39 @@ namespace Nitrogen
_list().selectionModel()->select( index, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
_list().selectionModel()->setCurrentIndex( index, QItemSelectionModel::Current|QItemSelectionModel::Rows );
}
_resizeColumns();
emit changed();
return;
}
//_______________________________________________________
void NitrogenExceptionListWidget::_edit( void )
{
// retrieve selection
QModelIndex current( _list().selectionModel()->currentIndex() );
if( !current.isValid() ) return;
NitrogenException& exception( _model().get( current ) );
// create dialog
NitrogenExceptionDialog dialog( this );
dialog.setException( exception );
// map dialog
if( dialog.exec() == QDialog::Rejected ) return;
NitrogenException new_exception = dialog.exception();
// check if exception was changed
if( exception == new_exception ) return;
// check new exception validity
if( !_checkException( new_exception ) ) return;
// asign new exception
*&exception = new_exception;
*&exception = new_exception;
_resizeColumns();
emit changed();
return;
@ -208,24 +208,24 @@ namespace Nitrogen
_resizeColumns();
emit changed();
return;
}
//_______________________________________________________
void NitrogenExceptionListWidget::_toggle( const QModelIndex& index )
{
if( !index.isValid() ) return;
if( index.column() != NitrogenExceptionModel::ENABLED ) return;
// get matching exception
NitrogenException& exception( _model().get( index ) );
exception.setEnabled( !exception.enabled() );
_model().add( exception );
emit changed();
return;
}
//_______________________________________________________
@ -234,92 +234,92 @@ namespace Nitrogen
NitrogenExceptionModel::List selection( _model().get( _list().selectionModel()->selectedRows() ) );
if( selection.empty() ) { return; }
// retrieve selected indexes in list and store in model
QModelIndexList selected_indexes( _list().selectionModel()->selectedRows() );
NitrogenExceptionModel::List selected_exceptions( _model().get( selected_indexes ) );
NitrogenExceptionModel::List current_exceptions( _model().get() );
NitrogenExceptionModel::List new_exceptions;
for( NitrogenExceptionModel::List::const_iterator iter = current_exceptions.begin(); iter != current_exceptions.end(); iter++ )
{
// check if new list is not empty, current index is selected and last index is not.
// if yes, move.
if(
!( new_exceptions.empty() ||
if(
!( new_exceptions.empty() ||
selected_indexes.indexOf( _model().index( *iter ) ) == -1 ||
selected_indexes.indexOf( _model().index( new_exceptions.back() ) ) != -1
selected_indexes.indexOf( _model().index( new_exceptions.back() ) ) != -1
) )
{
{
NitrogenException last( new_exceptions.back() );
new_exceptions.pop_back();
new_exceptions.push_back( *iter );
new_exceptions.push_back( last );
} else new_exceptions.push_back( *iter );
}
_model().set( new_exceptions );
// restore selection
_list().selectionModel()->select( _model().index( selected_exceptions.front() ), QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
for( NitrogenExceptionModel::List::const_iterator iter = selected_exceptions.begin(); iter != selected_exceptions.end(); iter++ )
{ _list().selectionModel()->select( _model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); }
emit changed();
return;
}
//_______________________________________________________
void NitrogenExceptionListWidget::_down( void )
{
NitrogenExceptionModel::List selection( _model().get( _list().selectionModel()->selectedRows() ) );
if( selection.empty() )
{ return; }
// retrieve selected indexes in list and store in model
QModelIndexList selected_indexes( _list().selectionModel()->selectedIndexes() );
NitrogenExceptionModel::List selected_exceptions( _model().get( selected_indexes ) );
NitrogenExceptionModel::List current_exceptions( _model().get() );
NitrogenExceptionModel::List new_exceptions;
for( NitrogenExceptionModel::List::reverse_iterator iter = current_exceptions.rbegin(); iter != current_exceptions.rend(); iter++ )
{
// check if new list is not empty, current index is selected and last index is not.
// if yes, move.
if(
!( new_exceptions.empty() ||
if(
!( new_exceptions.empty() ||
selected_indexes.indexOf( _model().index( *iter ) ) == -1 ||
selected_indexes.indexOf( _model().index( new_exceptions.back() ) ) != -1
selected_indexes.indexOf( _model().index( new_exceptions.back() ) ) != -1
) )
{
{
NitrogenException last( new_exceptions.back() );
new_exceptions.pop_back();
new_exceptions.push_back( *iter );
new_exceptions.push_back( last );
} else new_exceptions.push_back( *iter );
}
_model().set( NitrogenExceptionModel::List( new_exceptions.rbegin(), new_exceptions.rend() ) );
// restore selection
_list().selectionModel()->select( _model().index( selected_exceptions.front() ), QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
for( NitrogenExceptionModel::List::const_iterator iter = selected_exceptions.begin(); iter != selected_exceptions.end(); iter++ )
{ _list().selectionModel()->select( _model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); }
emit changed();
return;
}
//_______________________________________________________
void NitrogenExceptionListWidget::_resizeColumns( void ) const
{
@ -327,11 +327,11 @@ namespace Nitrogen
_list().resizeColumnToContents( NitrogenExceptionModel::TYPE );
_list().resizeColumnToContents( NitrogenExceptionModel::REGEXP );
}
//_______________________________________________________
bool NitrogenExceptionListWidget::_checkException( NitrogenException& exception )
{
while( !exception.regExp().isValid() )
{
@ -340,10 +340,10 @@ namespace Nitrogen
dialog.setException( exception );
if( dialog.exec() == QDialog::Rejected ) return false;
exception = dialog.exception();
}
return true;
}
}

View file

@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
// NitrogenExceptionListWidget.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,7 +22,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KPushButton>
@ -35,101 +35,101 @@
//! QDialog used to commit selected files
namespace Nitrogen
{
class NitrogenExceptionListWidget: public QWidget
{
//! Qt meta object
Q_OBJECT
public:
//! constructor
NitrogenExceptionListWidget( QWidget* = 0, NitrogenConfiguration default_configuration = NitrogenConfiguration() );
//! set exceptions
void setExceptions( const NitrogenExceptionList& );
//! get exceptions
NitrogenExceptionList exceptions( void ) const;
signals:
//! emited when list is changed
void changed( void );
protected:
//! list
QTreeView& _list() const
{ return *list_; }
//! model
const NitrogenExceptionModel& _model() const
{ return model_; }
//! model
NitrogenExceptionModel& _model()
{ return model_; }
protected slots:
//! update button states
virtual void _updateButtons( void );
//! add
virtual void _add( void );
//! edit
virtual void _edit( void );
//! remove
//! remove
virtual void _remove( void );
//! toggle
virtual void _toggle( const QModelIndex& );
//! move up
virtual void _up( void );
//! move down
virtual void _down( void );
private:
//! resize columns
void _resizeColumns( void ) const;
//! check exception
bool _checkException( NitrogenException& );
//! default configuration
NitrogenConfiguration default_configuration_;
//! list of files
QTreeView* list_;
//! model
NitrogenExceptionModel model_;
//! add
KPushButton* add_button_;
//! edit
KPushButton* edit_button_;
//! remove
KPushButton* remove_button_;
//! move up
KPushButton* up_button_;
//! move down
KPushButton* down_button_;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptionmodel.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,36 +20,36 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include "nitrogenexceptionmodel.h"
#include <KLocale>
namespace Nitrogen
{
//_______________________________________________
const QString NitrogenExceptionModel::column_titles_[ NitrogenExceptionModel::n_columns ] =
{
{
"",
i18n("Exception Type"),
i18n("Regular Expression")
};
//__________________________________________________________________
QVariant NitrogenExceptionModel::data( const QModelIndex& index, int role ) const
{
// check index, role and column
if( !index.isValid() ) return QVariant();
// retrieve associated file info
const NitrogenException& exception( get(index) );
// return text associated to file and column
if( role == Qt::DisplayRole )
if( role == Qt::DisplayRole )
{
switch( index.column() )
{
case TYPE: return exception.typeName();
@ -57,35 +57,35 @@ namespace Nitrogen
default: return QVariant();
break;
}
} else if( role == Qt::CheckStateRole && index.column() == ENABLED ) {
return exception.enabled() ? Qt::Checked : Qt::Unchecked;
} else if( role == Qt::ToolTipRole && index.column() == ENABLED ) {
return i18n("Enable/disable this exception");
}
return QVariant();
}
//__________________________________________________________________
QVariant NitrogenExceptionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(
orientation == Qt::Horizontal &&
role == Qt::DisplayRole &&
section >= 0 &&
if(
orientation == Qt::Horizontal &&
role == Qt::DisplayRole &&
section >= 0 &&
section < n_columns )
{ return column_titles_[section]; }
// return empty
return QVariant();
return QVariant();
}
}

View file

@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptionmodel.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,60 +22,60 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include "listmodel.h"
#include "../nitrogenexception.h"
namespace Nitrogen
{
//! qlistview for object counters
class NitrogenExceptionModel: public ListModel<NitrogenException>
{
public:
//! number of columns
enum { n_columns = 3 };
//! column type enumeration
enum ColumnType {
ENABLED,
TYPE,
REGEXP
};
//!@name methods reimplemented from base class
//@{
// return data for a given index
virtual QVariant data(const QModelIndex &index, int role) const;
//! header data
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
//! number of columns for a given index
virtual int columnCount(const QModelIndex& ) const
{ return n_columns; }
//@}
//@}
protected:
//! sort
virtual void _sort( int, Qt::SortOrder )
{}
private:
//! column titles
static const QString column_titles_[ n_columns ];
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogen.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
//
@ -21,7 +21,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <cassert>
@ -45,67 +45,67 @@ extern "C"
namespace Nitrogen
{
// referenced from definition in Nitrogendclient.cpp
OxygenHelper *nitrogenHelper();
OxygenHelper *nitrogenHelper();
// initialize static members
bool NitrogenFactory::initialized_ = false;
NitrogenConfiguration NitrogenFactory::defaultConfiguration_;
NitrogenExceptionList NitrogenFactory::exceptions_;
//___________________________________________________
NitrogenFactory::NitrogenFactory()
{
readConfig();
setInitialized( true );
}
//___________________________________________________
NitrogenFactory::~NitrogenFactory()
NitrogenFactory::~NitrogenFactory()
{ setInitialized( false ); }
//___________________________________________________
KDecoration* NitrogenFactory::createDecoration(KDecorationBridge* bridge )
{
{
NitrogenClient* client( new NitrogenClient( bridge, this ) );
connect( this, SIGNAL( configurationChanged() ), client, SLOT( resetConfiguration() ) );
return client->decoration();
return client->decoration();
}
//___________________________________________________
bool NitrogenFactory::reset(unsigned long changed)
{
kDebug( 1212 ) << endl;
// read in the configuration
setInitialized( false );
bool configuration_changed = readConfig();
setInitialized( true );
if( configuration_changed || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
{
if( configuration_changed || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
{
emit configurationChanged();
return true;
return true;
} else {
emit configurationChanged();
resetDecorations(changed);
return false;
}
}
//___________________________________________________
bool NitrogenFactory::readConfig()
{
kDebug( 1212 ) << endl;
// create a config object
KConfig config("nitrogenrc");
KConfigGroup group( config.group("Windeco") );
@ -114,34 +114,34 @@ namespace Nitrogen
// read exceptionsreadConfig
NitrogenExceptionList exceptions( config );
if( !( exceptions == exceptions_ ) )
if( !( exceptions == exceptions_ ) )
{
exceptions_ = exceptions;
exceptions_ = exceptions;
changed = true;
}
if( changed )
if( changed )
{
nitrogenHelper()->invalidateCaches();
setDefaultConfiguration( configuration );
return true;
} else return false;
}
//_________________________________________________________________
bool NitrogenFactory::supports( Ability ability ) const
{
switch( ability )
switch( ability )
{
// announce
case AbilityAnnounceButtons:
case AbilityAnnounceColors:
// buttons
case AbilityButtonMenu:
case AbilityButtonHelp:
@ -153,50 +153,50 @@ namespace Nitrogen
case AbilityButtonBelowOthers:
case AbilityButtonSpacer:
case AbilityButtonShade:
// // colors
// case AbilityColorTitleBack:
// case AbilityColorTitleFore:
// case AbilityColorFrame:
// compositing
case AbilityProvidesShadow: // TODO: UI option to use default shadows instead
case AbilityUsesAlphaChannel:
return true;
// no colors supported at this time
default:
return false;
};
}
//____________________________________________________________________
NitrogenConfiguration NitrogenFactory::configuration( const NitrogenClient& client )
{
QString window_title;
QString class_name;
for( NitrogenExceptionList::const_iterator iter = exceptions_.constBegin(); iter != exceptions_.constEnd(); iter++ )
{
// discard disabled exceptions
if( !iter->enabled() ) continue;
/*
/*
decide which value is to be compared
to the regular expression, based on exception type
*/
QString value;
switch( iter->type() )
{
case NitrogenException::WindowTitle:
case NitrogenException::WindowTitle:
{
value = window_title.isEmpty() ? (window_title = client.caption()):window_title;
break;
}
case NitrogenException::WindowClassName:
{
if( class_name.isEmpty() )
@ -206,34 +206,34 @@ namespace Nitrogen
QString window_class_name( info.windowClassName() );
QString window_class( info.windowClassClass() );
class_name = window_class_name + " " + window_class;
}
}
value = class_name;
break;
}
default: assert( false );
}
if( iter->regExp().indexIn( value ) < 0 ) continue;
NitrogenConfiguration configuration( defaultConfiguration() );
// propagate all features found in mask to the output configuration
if( iter->mask() & NitrogenException::FrameBorder ) configuration.setFrameBorder( iter->frameBorder() );
if( iter->mask() & NitrogenException::BlendColor ) configuration.setBlendColor( iter->blendColor() );
if( iter->mask() & NitrogenException::DrawSeparator ) configuration.setDrawSeparator( iter->drawSeparator() );
if( iter->mask() & NitrogenException::TitleOutline ) configuration.setDrawTitleOutline( iter->drawTitleOutline() );
if( iter->mask() & NitrogenException::SizeGripMode ) configuration.setSizeGripMode( iter->sizeGripMode() );
return configuration;
}
return defaultConfiguration();
}
} //namespace Nitrogen

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogen.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira <hugo.pereira@free.fr>
// Copyright (c) 2006, 2007 Riccardo Iaconelli <ruphy@fsfe.org>
//
@ -24,7 +24,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QObject>
@ -39,14 +39,14 @@
namespace Nitrogen
{
class NitrogenClient;
//! button size
// enum { NITROGEN_BUTTONSIZE = 22 };
//! buttons
enum ButtonType
enum ButtonType
{
ButtonHelp=0,
ButtonMax,
@ -61,85 +61,85 @@ namespace Nitrogen
};
static const qreal SHADOW_WIDTH = 25.5;
/*
/*
If non zero, this possibly allow one to have an additional space
around window that is clickable although it is part of the shadow
*/
around window that is clickable although it is part of the shadow
*/
static const int EXTENDED_HITAREA = 0;
// this is the top title bar edge
static const int TFRAMESIZE = 3;
// this is the extra title bar top and bottom edges
// needed to outline active window title bar
static const int HFRAMESIZE = 4;
Q_DECLARE_FLAGS(ButtonTypes, ButtonType)
//! window decoration factory
class NitrogenFactory: public QObject, public KDecorationFactoryUnstable
{
Q_OBJECT
public:
//! constructor
NitrogenFactory();
//! destructor
virtual ~NitrogenFactory();
//! create decoration
virtual KDecoration *createDecoration(KDecorationBridge *b);
//! configuration reset
virtual bool reset(unsigned long changed);
//! configuration capabilities
virtual bool supports( Ability ability ) const;
//! true if initialized
static bool initialized()
{ return initialized_; }
//! get configuration for a give client
static NitrogenConfiguration configuration( const NitrogenClient& );
signals:
//! configuration has changed
void configurationChanged( void );
private:
//! read configuration from KConfig
bool readConfig();
//! default configuration
static NitrogenConfiguration defaultConfiguration( void )
{ return defaultConfiguration_; }
//! initialization
static void setInitialized( bool value )
{ initialized_ = value; }
//! set default configuration
static void setDefaultConfiguration( NitrogenConfiguration value )
{ defaultConfiguration_ = value; }
//! initialization flag
static bool initialized_;
//! default configuration
static NitrogenConfiguration defaultConfiguration_;
//! exceptions
static NitrogenExceptionList exceptions_;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenbutton.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
@ -22,7 +22,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <cmath>
@ -43,60 +43,60 @@ namespace Nitrogen
//_______________________________________________
NitrogenButton::NitrogenButton(NitrogenClient &parent,
const QString& tip, ButtonType type):
KCommonDecorationButton((::ButtonType)type, &parent),
client_(parent),
helper_( parent.helper() ),
type_(type),
KCommonDecorationButton((::ButtonType)type, &parent),
client_(parent),
helper_( parent.helper() ),
type_(type),
colorCacheInvalid_(true)
{
setAutoFillBackground(false);
setAttribute(Qt::WA_NoSystemBackground);
{
unsigned int size( client_.configuration().buttonSize() );
setFixedSize( size, size );
}
setCursor(Qt::ArrowCursor);
setToolTip(tip);
}
//_______________________________________________
NitrogenButton::~NitrogenButton()
{}
//declare function from Nitrogenclient.cpp
QColor reduceContrast(const QColor &c0, const QColor &c1, double t);
//_______________________________________________
QColor NitrogenButton::buttonDetailColor(const QPalette &palette)
{
if (client_.isActive()) return palette.color(QPalette::Active, QPalette::ButtonText);
else {
if (colorCacheInvalid_)
if (colorCacheInvalid_)
{
QColor ab = palette.color(QPalette::Active, QPalette::Button);
QColor af = palette.color(QPalette::Active, QPalette::ButtonText);
QColor nb = palette.color(QPalette::Inactive, QPalette::Button);
QColor nf = palette.color(QPalette::Inactive, QPalette::ButtonText);
colorCacheInvalid_ = false;
cachedButtonDetailColor_ = reduceContrast(nb, nf, qMax(qreal(2.5), KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4))));
}
return cachedButtonDetailColor_;
}
}
//___________________________________________________
QSize NitrogenButton::sizeHint() const
{
{
unsigned int size( client_.configuration().buttonSize() );
return QSize( size, size );
}
//___________________________________________________
void NitrogenButton::enterEvent(QEvent *e)
{
@ -104,7 +104,7 @@ namespace Nitrogen
if (status_ != Nitrogen::Pressed) status_ = Nitrogen::Hovered;
update();
}
//___________________________________________________
void NitrogenButton::leaveEvent(QEvent *e)
{
@ -112,76 +112,76 @@ namespace Nitrogen
status_ = Nitrogen::Normal;
update();
}
//___________________________________________________
void NitrogenButton::mousePressEvent(QMouseEvent *e)
{
status_ = Nitrogen::Pressed;
update();
KCommonDecorationButton::mousePressEvent(e);
}
//___________________________________________________
void NitrogenButton::mouseReleaseEvent(QMouseEvent *e)
{
status_ = Nitrogen::Normal;
update();
KCommonDecorationButton::mouseReleaseEvent(e);
}
//___________________________________________________
void NitrogenButton::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setClipRect(this->rect().intersected( event->rect() ) );
QPalette palette = NitrogenButton::palette();
QPalette palette = NitrogenButton::palette();
if( client_.isActive() ) palette.setCurrentColorGroup(QPalette::Active);
else palette.setCurrentColorGroup(QPalette::Inactive);
client_.renderWindowBackground( &painter, rect(), this, palette );
if( client_.isActive() && client_.configuration().drawTitleOutline() && !client_.isMaximized() )
{ client_.renderWindowBorder( &painter, rect(), this, palette ); }
// draw dividing line
painter.setRenderHints(QPainter::Antialiasing);
QRect frame = client_.widget()->rect();
int x = -this->geometry().x()+1;
int w = frame.width()-2;
const int titleHeight = client_.layoutMetric(KCommonDecoration::LM_TitleHeight);
QColor color = palette.window().color();
QColor light = helper_.calcLightColor( color );
QColor dark = helper_.calcDarkColor( color );
dark.setAlpha(120);
if( client_.drawSeparator() )
if( client_.drawSeparator() )
{ helper_.drawSeparator(&painter, QRect(x, titleHeight-1.5, w, 2), color, Qt::Horizontal); }
// for menu button the application icon is used
if (type_ == ButtonMenu)
if (type_ == ButtonMenu)
{
const QPixmap& pixmap( client_.icon().pixmap( client_.configuration().iconScale() ) );
double offset = 0.5*(width()-pixmap.width() );
painter.drawPixmap(offset, offset-1, pixmap );
return;
}
color = buttonDetailColor(palette);
if(status_ == Nitrogen::Hovered || status_ == Nitrogen::Pressed)
if(status_ == Nitrogen::Hovered || status_ == Nitrogen::Pressed)
{
if(type_ == ButtonClose) color = KColorScheme(palette.currentColorGroup()).foreground(KColorScheme::NegativeText).color();
else color = KColorScheme(palette.currentColorGroup()).decoration(KColorScheme::HoverColor).color();
}
// translate buttons up if window maximized
if(client_.isMaximized())
{ painter.translate( 0, -1 ); }
@ -191,23 +191,23 @@ namespace Nitrogen
// draw button shape
painter.drawPixmap(0, 0, helper_.windecoButton(bt, status_ == Nitrogen::Pressed, (21.0*client_.configuration().buttonSize())/22 ) );
// draw glow on hover
if( status_ == Nitrogen::Hovered )
if( status_ == Nitrogen::Hovered )
{ painter.drawPixmap(0, 0, helper_.windecoButtonGlow(color, (21.0*client_.configuration().buttonSize())/22)); }
// draw button icon
if (client_.isActive())
if (client_.isActive())
{
QLinearGradient lg = helper_.decoGradient( QRect( 4, 4, 13, 13 ), color);
painter.setRenderHints(QPainter::Antialiasing);
qreal width( 1.4 );
painter.setBrush(Qt::NoBrush);
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
drawIcon(&painter, palette, type_);
} else {
// outlined mode
@ -218,27 +218,27 @@ namespace Nitrogen
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(color, 3.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
drawIcon(&pp, palette, type_);
pp.setCompositionMode(QPainter::CompositionMode_DestinationOut);
pp.setPen(QPen(color, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
drawIcon(&pp, palette, type_);
painter.drawPixmap(QPoint(0,0), pixmap);
}
}
//___________________________________________________
void NitrogenButton::drawIcon(QPainter *painter, QPalette &palette, ButtonType &type)
{
painter->save();
painter->save();
painter->setWindow( 0, 0, 22, 22 );
QPen newPen = painter->pen();
switch(type)
{
case ButtonSticky:
if(isChecked()) {
newPen.setColor(KColorScheme(palette.currentColorGroup()).decoration(KColorScheme::HoverColor).color());
@ -246,7 +246,7 @@ namespace Nitrogen
}
painter->drawPoint(QPointF(10.5,10.5));
break;
case ButtonHelp:
painter->translate(1.5, 1.5);
painter->drawArc(7,5,4,4,135*16, -180*16);
@ -254,12 +254,12 @@ namespace Nitrogen
painter->drawPoint(9,12);
painter->translate(-1.5, -1.5);
break;
case ButtonMin:
painter->drawLine(QPointF( 7.5, 9.5), QPointF(10.5,12.5));
painter->drawLine(QPointF(10.5,12.5), QPointF(13.5, 9.5));
break;
case ButtonMax:
switch(client_.maximizeMode())
{
@ -269,7 +269,7 @@ namespace Nitrogen
painter->drawLine(QPointF( 7.5,11.5), QPointF(10.5, 8.5));
painter->drawLine(QPointF(10.5, 8.5), QPointF(13.5,11.5));
break;
case NitrogenClient::MaximizeFull:
{
painter->translate(1.5, 1.5);
@ -280,62 +280,62 @@ namespace Nitrogen
}
}
break;
case ButtonClose:
painter->drawLine(QPointF( 7.5,7.5), QPointF(13.5,13.5));
painter->drawLine(QPointF(13.5,7.5), QPointF( 7.5,13.5));
break;
case ButtonAbove:
if(isChecked()) {
QPen newPen = painter->pen();
newPen.setColor(KColorScheme(palette.currentColorGroup()).decoration(KColorScheme::HoverColor).color());
painter->setPen(newPen);
}
painter->drawLine(QPointF( 7.5,14), QPointF(10.5,11));
painter->drawLine(QPointF(10.5,11), QPointF(13.5,14));
painter->drawLine(QPointF( 7.5,10), QPointF(10.5, 7));
painter->drawLine(QPointF(10.5, 7), QPointF(13.5,10));
break;
case ButtonBelow:
if(isChecked()) {
QPen newPen = painter->pen();
newPen.setColor(KColorScheme(palette.currentColorGroup()).decoration(KColorScheme::HoverColor).color());
painter->setPen(newPen);
}
painter->drawLine(QPointF( 7.5,11), QPointF(10.5,14));
painter->drawLine(QPointF(10.5,14), QPointF(13.5,11));
painter->drawLine(QPointF( 7.5, 7), QPointF(10.5,10));
painter->drawLine(QPointF(10.5,10), QPointF(13.5, 7));
break;
case ButtonShade:
if (!isChecked())
if (!isChecked())
{
// shade button
painter->drawLine(QPointF( 7.5, 7.5), QPointF(10.5,10.5));
painter->drawLine(QPointF(10.5,10.5), QPointF(13.5, 7.5));
painter->drawLine(QPointF( 7.5,13.0), QPointF(13.5,13.0));
} else {
} else {
// unshade button
painter->drawLine(QPointF( 7.5,10.5), QPointF(10.5, 7.5));
painter->drawLine(QPointF(10.5, 7.5), QPointF(13.5,10.5));
painter->drawLine(QPointF( 7.5,13.0), QPointF(13.5,13.0));
}
break;
default:
break;
}
painter->restore();
return;
}
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenbutton.h
// -------------------
//
//
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
@ -36,87 +36,87 @@
namespace Nitrogen
{
class NitrogenClient;
enum ButtonStatus {
Normal,
Hovered,
Pressed
Pressed
};
Q_DECLARE_FLAGS(ButtonState, ButtonStatus)
class NitrogenButton : public KCommonDecorationButton
{
public:
//! constructor
explicit NitrogenButton(NitrogenClient &parent,
const QString &tip=NULL,
ButtonType type=ButtonHelp);
//! destructor
~NitrogenButton();
//! destructor
QSize sizeHint() const;
//! last button mouse
// int lastMousePress() const
// int lastMousePress() const
// {return lastmouse_;}
//! reset
void reset(long unsigned int)
{repaint();}
//! button type
ButtonType type( void ) const
{ return type_; }
protected:
//! press event
void mousePressEvent(QMouseEvent* );
//! release event
void mouseReleaseEvent(QMouseEvent* );
//! enter event
void enterEvent( QEvent* );
//! leave event
void leaveEvent(QEvent* );
//! paint
void paintEvent(QPaintEvent* );
private:
//! draw icon
void drawIcon(QPainter*, QPalette&, ButtonType& );
//! color
QColor buttonDetailColor(const QPalette& );
private:
//! parent client
NitrogenClient &client_;
//! helper
OxygenHelper &helper_;
//! button type
ButtonType type_;
//! button status
ButtonState status_;
//! last button mouse pressed
int lastmouse_;
bool colorCacheInvalid_;
QColor cachedButtonDetailColor_;
};
} //namespace Nitrogen
#endif

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenclient.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright (c) 2003, 2004 David Johnson <david@usermode.org>
// Copyright (c) 2006, 2007 Riccardo Iaconelli <ruphy@fsfe.org>
@ -25,7 +25,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <kcommondecoration.h>
@ -36,172 +36,172 @@
#include "lib/tileset.h"
namespace Nitrogen
namespace Nitrogen
{
class NitrogenSizeGrip;
class NitrogenClient : public KCommonDecorationUnstable
{
Q_OBJECT
public:
//! constructor
NitrogenClient(KDecorationBridge *b, KDecorationFactory *f);
//! destructor
virtual ~NitrogenClient();
virtual QString visibleName() const;
virtual KCommonDecorationButton *createButton(::ButtonType type);
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
//! true if window is maximized
virtual bool isMaximized( void ) const;
//! true when separator is to be drawn
virtual bool drawSeparator( void ) const
{ return isActive() && configuration().drawSeparator() && !configuration().drawTitleOutline(); }
//! true when oxygen 'glow' shadow is to be drawn for active window
virtual bool useOxygenShadows( void ) const
{ return isActive() && configuration().useOxygenShadows(); }
//! dimensions
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const;
//! window shape
virtual void updateWindowShape();
//! initialization
virtual void init();
//! return associated configuration
NitrogenConfiguration configuration( void ) const;
//! helper class
OxygenHelper& helper( void ) const
{ return helper_; }
//! window background
virtual void renderWindowBackground( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
//! window border
// this draws a "blue" border around active window
virtual void renderWindowBorder( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
//! title outline
virtual void renderTitleOutline( QPainter*, const QRect&, const QPalette& ) const;
//! triggered when window activity is changed
virtual void activeChange();
//! triggered when maximize state changed
virtual void maximizeChange();
//! triggered when window shade is changed
virtual void shadeChange();
public slots:
//! reset configuration
void resetConfiguration( void );
protected:
//! paint
void paintEvent( QPaintEvent* );
//! shadows
TileSet *shadowTiles(const QColor& color, const QColor& glow, qreal size, bool active);
//! shadows
QPixmap shadowPixmap( const QColor& color, const QColor& glow, qreal size) const;
private:
class ShadowTilesOption {
public:
//! constructor
ShadowTilesOption( void ):
width(0),
active(false)
{}
//! equal to operator
bool operator == ( const ShadowTilesOption& other ) const
{
return
return
windowColor == other.windowColor &&
glowColor == other.glowColor &&
width == other.width &&
active == other.active;
}
QColor windowColor;
QColor glowColor;
qreal width;
bool active;
};
//! palette background
QPalette backgroundPalette( const QWidget*, QPalette ) const;
//! calculate mask
QRegion calcMask( void ) const;
//! text color
QColor titlebarTextColor(const QPalette&);
//!@name size grip
//@{
//! create size grip
void createSizeGrip( void );
//! delete size grip
void deleteSizeGrip( void );
// size grip
bool hasSizeGrip( void ) const
{ return (bool)size_grip_; }
//! size grip
NitrogenSizeGrip& sizeGrip( void ) const
{ return *size_grip_; }
//@}
//! configuration
NitrogenConfiguration configuration_;
//! used to invalidate color cache
bool colorCacheInvalid_;
//! stored color
QColor cachedTitlebarTextColor_;
//! size grip widget
NitrogenSizeGrip* size_grip_;
ShadowTilesOption shadowTilesOption_;
ShadowTilesOption shadowTilesOption_;
ShadowTilesOption glowTilesOption_;
TileSet *shadowTiles_;
TileSet *shadowTiles_;
TileSet *glowTiles_;
//! helper
OxygenHelper& helper_;
OxygenHelper& helper_;
//! true when initialized
bool initialized_;
};
} // namespace Nitrogen
#endif // EXAMPLECLIENT_H

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenconfiguration.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KLocale>
@ -33,7 +33,7 @@
namespace Nitrogen
{
//__________________________________________________
NitrogenConfiguration::NitrogenConfiguration( void ):
titleAlignment_( Qt::AlignLeft ),
@ -48,68 +48,68 @@ namespace Nitrogen
//__________________________________________________
NitrogenConfiguration::NitrogenConfiguration( KConfigGroup group )
{
{
// used to set default values when entries are not found in kconfig
NitrogenConfiguration defaultConfiguration;
// title alignment
setTitleAlignment( titleAlignment(
group.readEntry( NitrogenConfig::TITLE_ALIGNMENT,
setTitleAlignment( titleAlignment(
group.readEntry( NitrogenConfig::TITLE_ALIGNMENT,
defaultConfiguration.titleAlignmentName( false ) ), false ) );
// button size
setButtonSize( buttonSize(
setButtonSize( buttonSize(
group.readEntry( NitrogenConfig::BUTTON_SIZE,
defaultConfiguration.buttonSizeName( false ) ), false ) );
// frame border
setFrameBorder( frameBorder(
group.readEntry( NitrogenConfig::FRAME_BORDER,
setFrameBorder( frameBorder(
group.readEntry( NitrogenConfig::FRAME_BORDER,
defaultConfiguration.frameBorderName( false ) ), false ) );
// blend color
setBlendColor( blendColor(
group.readEntry( NitrogenConfig::BLEND_COLOR,
group.readEntry( NitrogenConfig::BLEND_COLOR,
defaultConfiguration.blendColorName( false ) ), false ) );
// size grip
setSizeGripMode( sizeGripMode(
group.readEntry( NitrogenConfig::SIZE_GRIP_MODE,
setSizeGripMode( sizeGripMode(
group.readEntry( NitrogenConfig::SIZE_GRIP_MODE,
defaultConfiguration.sizeGripModeName( false ) ), false ) );
// draw separator
setDrawSeparator( group.readEntry(
NitrogenConfig::DRAW_SEPARATOR,
setDrawSeparator( group.readEntry(
NitrogenConfig::DRAW_SEPARATOR,
defaultConfiguration.drawSeparator() ) );
// title outline
setDrawTitleOutline( group.readEntry(
NitrogenConfig::DRAW_TITLE_OUTLINE,
setDrawTitleOutline( group.readEntry(
NitrogenConfig::DRAW_TITLE_OUTLINE,
defaultConfiguration.drawTitleOutline() ) );
// oxygen shadows
setUseOxygenShadows( group.readEntry(
NitrogenConfig::USE_OXYGEN_SHADOWS,
defaultConfiguration.useOxygenShadows() ) );
}
//__________________________________________________
void NitrogenConfiguration::write( KConfigGroup& group ) const
{
group.writeEntry( NitrogenConfig::TITLE_ALIGNMENT, titleAlignmentName( false ) );
group.writeEntry( NitrogenConfig::BUTTON_SIZE, buttonSizeName( false ) );
group.writeEntry( NitrogenConfig::BLEND_COLOR, blendColorName( false ) );
group.writeEntry( NitrogenConfig::FRAME_BORDER, frameBorderName( false ) );
group.writeEntry( NitrogenConfig::SIZE_GRIP_MODE, sizeGripModeName( false ) );
group.writeEntry( NitrogenConfig::DRAW_SEPARATOR, drawSeparator() );
group.writeEntry( NitrogenConfig::DRAW_TITLE_OUTLINE, drawTitleOutline() );
group.writeEntry( NitrogenConfig::USE_OXYGEN_SHADOWS, useOxygenShadows() );
}
//__________________________________________________
QString NitrogenConfiguration::titleAlignmentName( Qt::Alignment value, bool translated )
{
@ -121,11 +121,11 @@ namespace Nitrogen
case Qt::AlignRight: out = "Right"; break;
default: return NitrogenConfiguration().titleAlignmentName( translated );
}
return translated ? i18n(out):out;
}
//__________________________________________________
Qt::Alignment NitrogenConfiguration::titleAlignment( QString value, bool translated )
{
@ -134,7 +134,7 @@ namespace Nitrogen
else if (value == titleAlignmentName( Qt::AlignRight, translated ) ) return Qt::AlignRight;
else return NitrogenConfiguration().titleAlignment();
}
//__________________________________________________
QString NitrogenConfiguration::buttonSizeName( ButtonSize value, bool translated )
{
@ -147,9 +147,9 @@ namespace Nitrogen
case ButtonHuge: out = "Huge"; break;
default: return NitrogenConfiguration().buttonSizeName( translated );
}
return translated ? i18n(out):out;
}
//__________________________________________________
@ -168,14 +168,14 @@ namespace Nitrogen
switch( value )
{
case ButtonSmall: return 13;
case ButtonDefault: return 16;
case ButtonDefault: return 16;
case ButtonLarge: return 24;
case ButtonHuge: return 35;
default: return NitrogenConfiguration().iconScale();
}
}
//__________________________________________________
QString NitrogenConfiguration::frameBorderName( FrameBorder value, bool translated )
{
@ -192,11 +192,11 @@ namespace Nitrogen
case BorderOversized: out = "Oversized"; break;
default: return NitrogenConfiguration().frameBorderName( translated );
}
return translated ? i18n(out):out;
}
//__________________________________________________
NitrogenConfiguration::FrameBorder NitrogenConfiguration::frameBorder( QString value, bool translated )
{
@ -210,7 +210,7 @@ namespace Nitrogen
else if( value == frameBorderName( BorderOversized, translated ) ) return BorderOversized;
else return NitrogenConfiguration().frameBorder();
}
//__________________________________________________
QString NitrogenConfiguration::blendColorName( BlendColorType value, bool translated )
{
@ -221,11 +221,11 @@ namespace Nitrogen
case RadialBlending: out = "Radial Gradient"; break;
default: return NitrogenConfiguration().blendColorName( translated );
}
return translated ? i18n(out):out;
}
//__________________________________________________
NitrogenConfiguration::BlendColorType NitrogenConfiguration::blendColor( QString value, bool translated )
{
@ -233,7 +233,7 @@ namespace Nitrogen
else if( value == blendColorName( RadialBlending, translated ) ) return RadialBlending;
else return NitrogenConfiguration().blendColor();
}
//__________________________________________________
QString NitrogenConfiguration::sizeGripModeName( SizeGripMode value, bool translated )
{
@ -244,11 +244,11 @@ namespace Nitrogen
case SizeGripWhenNeeded: out = "Show Extra Size Grip When Needed"; break;
default: return NitrogenConfiguration().sizeGripModeName( translated );
}
return translated ? i18n(out):out;
}
//__________________________________________________
NitrogenConfiguration::SizeGripMode NitrogenConfiguration::sizeGripMode( QString value, bool translated )
{
@ -256,11 +256,11 @@ namespace Nitrogen
else if( value == sizeGripModeName( SizeGripWhenNeeded, translated ) ) return SizeGripWhenNeeded;
else return NitrogenConfiguration().sizeGripMode();
}
//________________________________________________________
bool NitrogenConfiguration::operator == (const NitrogenConfiguration& other ) const
{
return
titleAlignment() == other.titleAlignment() &&
buttonSize() == other.buttonSize() &&

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenconfiguration.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,14 +23,14 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KConfigGroup>
namespace NitrogenConfig
{
static const QString TITLE_ALIGNMENT = "TitleAlignment";
static const QString BUTTON_SIZE = "ButtonSize";
static const QString DRAW_SEPARATOR = "DrawSeparator";
@ -39,7 +39,7 @@ namespace NitrogenConfig
static const QString BLEND_COLOR = "BlendColor";
static const QString SIZE_GRIP_MODE = "SizeGripMode";
static const QString USE_OXYGEN_SHADOWS = "UseOxygenShadows";
}
namespace Nitrogen
@ -47,7 +47,7 @@ namespace Nitrogen
class NitrogenConfiguration
{
public:
//! button size enumeration
@ -58,7 +58,7 @@ namespace Nitrogen
ButtonLarge = 32,
ButtonHuge = 48
};
//! frame border enumeration
enum FrameBorder
{
@ -77,36 +77,36 @@ namespace Nitrogen
NoBlending,
RadialBlending
};
//! size grip mode
enum SizeGripMode
{
SizeGripNever,
SizeGripWhenNeeded
};
//! default constructor
NitrogenConfiguration( void );
//! constructor from KConfig
NitrogenConfiguration( KConfigGroup );
//! destructor
virtual ~NitrogenConfiguration( void )
{}
//! equal to operator
bool operator == ( const NitrogenConfiguration& ) const;
//! write to kconfig group
virtual void write( KConfigGroup& ) const;
//!@name title alignment
//@{
static QString titleAlignmentName( Qt::Alignment, bool translated );
static Qt::Alignment titleAlignment( QString, bool translated );
virtual Qt::Alignment titleAlignment() const
{ return titleAlignment_; }
@ -115,59 +115,59 @@ namespace Nitrogen
virtual void setTitleAlignment( Qt::Alignment value )
{ titleAlignment_ = value; }
virtual void setTitleAlignment( QString value, bool translated )
{ titleAlignment_ = titleAlignment( value, translated ); }
//@}
//!@name button size
//@{
static QString buttonSizeName( ButtonSize, bool translated );
static ButtonSize buttonSize( QString, bool translated );
static int iconScale( ButtonSize );
virtual ButtonSize buttonSize( void ) const
{ return buttonSize_; }
virtual int iconScale( void ) const
{ return iconScale( buttonSize() ); }
virtual QString buttonSizeName( bool translated ) const
{ return buttonSizeName( buttonSize(), translated ); }
virtual void setButtonSize( ButtonSize value )
{ buttonSize_ = value; }
//@}
//!@name frame border
//@{
static QString frameBorderName( FrameBorder, bool translated );
static FrameBorder frameBorder( QString, bool translated );
virtual FrameBorder frameBorder() const
{ return frameBorder_; }
virtual QString frameBorderName( bool translated ) const
{ return frameBorderName( frameBorder(), translated ); }
virtual void setFrameBorder( FrameBorder value )
{ frameBorder_ = value; }
virtual void setFrameBorder( QString value, bool translated )
{ frameBorder_ = frameBorder( value, translated ); }
//@}
//!@name blend color
//@{
static QString blendColorName( BlendColorType, bool translated );
static BlendColorType blendColor( QString, bool translated );
virtual BlendColorType blendColor( void ) const
{ return blendColor_; }
@ -175,19 +175,19 @@ namespace Nitrogen
{ return blendColorName( blendColor(), translated ); }
virtual void setBlendColor( BlendColorType value )
{ blendColor_ = value; }
{ blendColor_ = value; }
virtual void setBlendColor( QString value, bool translated )
{ blendColor_ = blendColor( value, translated ); }
{ blendColor_ = blendColor( value, translated ); }
//@}
//!@name size grip
//@{
static QString sizeGripModeName( SizeGripMode, bool translated );
static SizeGripMode sizeGripMode( QString, bool translated );
virtual SizeGripMode sizeGripMode( void ) const
{ return sizeGripMode_; }
@ -195,21 +195,21 @@ namespace Nitrogen
{ return sizeGripModeName( sizeGripMode(), translated ); }
virtual void setSizeGripMode( SizeGripMode value )
{ sizeGripMode_ = value; }
{ sizeGripMode_ = value; }
virtual void setSizeGripMode( QString value, bool translated )
{ sizeGripMode_ = sizeGripMode( value, translated ); }
{ sizeGripMode_ = sizeGripMode( value, translated ); }
//! draw size grip
virtual bool drawSizeGrip( void ) const
{ return (sizeGripMode() == SizeGripWhenNeeded && frameBorder() == BorderNone ); }
//@}
//! separator
virtual bool drawSeparator( void ) const
{ return drawSeparator_; }
//! separator
virtual void setDrawSeparator( bool value )
{ drawSeparator_ = value; }
@ -217,7 +217,7 @@ namespace Nitrogen
//! title outline
virtual bool drawTitleOutline( void ) const
{ return drawTitleOutline_; }
//! title outline
virtual void setDrawTitleOutline( bool value )
{ drawTitleOutline_ = value; }
@ -225,39 +225,39 @@ namespace Nitrogen
//! oxygen shadows
virtual bool useOxygenShadows( void ) const
{ return useOxygenShadows_; }
//! oxygen shadows
virtual void setUseOxygenShadows( bool value )
{ useOxygenShadows_ = value; }
private:
//! title alignment
//! title alignment
Qt::Alignment titleAlignment_;
//! button size
ButtonSize buttonSize_;
//! blend color
FrameBorder frameBorder_;
FrameBorder frameBorder_;
//! frame border
BlendColorType blendColor_;
//! size grip mode
SizeGripMode sizeGripMode_;
//! separator
bool drawSeparator_;
//! active window title outline
bool drawTitleOutline_;
//! oxygen shadows
bool useOxygenShadows_;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexception.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <cassert>
@ -28,7 +28,7 @@
namespace Nitrogen
{
//_______________________________________________________
NitrogenException::NitrogenException( KConfigGroup group ):
NitrogenConfiguration( group )
@ -38,37 +38,37 @@ namespace Nitrogen
NitrogenException default_configuration;
// exception type
setType( type(
group.readEntry( NitrogenConfig::TYPE,
setType( type(
group.readEntry( NitrogenConfig::TYPE,
default_configuration.typeName() ) ) );
// exception pattern
regExp().setPattern( group.readEntry( NitrogenConfig::PATTERN, QString() ) );
// enability
setEnabled(
group.readEntry( NitrogenConfig::ENABLED,
default_configuration.enabled() ) );
// exception mask
setMask(
group.readEntry( NitrogenConfig::MASK,
setMask(
group.readEntry( NitrogenConfig::MASK,
default_configuration.mask() ) );
}
//_______________________________________________________
void NitrogenException::write( KConfigGroup& group ) const
{
NitrogenConfiguration::write( group );
group.writeEntry( NitrogenConfig::TYPE, typeName() );
group.writeEntry( NitrogenConfig::PATTERN, regExp().pattern() );
group.writeEntry( NitrogenConfig::ENABLED, enabled() );
group.writeEntry( NitrogenConfig::MASK, mask() );
}
//_______________________________________________________
QString NitrogenException::typeName( Type type )
{
@ -78,10 +78,10 @@ namespace Nitrogen
case WindowClassName: return "Window Class Name";
default: assert( false );
}
return QString();
}
//_______________________________________________________
NitrogenException::Type NitrogenException::type( const QString& value )
{
@ -89,5 +89,5 @@ namespace Nitrogen
else if( value == "Window Class Name" ) return WindowClassName;
else return WindowClassName;
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexception.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QRegExp>
@ -32,31 +32,31 @@
namespace NitrogenConfig
{
//! needed for exceptions
static const QString TYPE = "Type";
static const QString PATTERN = "Pattern";
static const QString ENABLED = "Enabled";
static const QString MASK = "Mask";
}
namespace Nitrogen
{
//! nitrogen exception
class NitrogenException: public NitrogenConfiguration
{
public:
//! exception type
enum Type
{
WindowTitle,
WindowClassName
};
//! mask
enum AttributesMask
{
@ -69,7 +69,7 @@ namespace Nitrogen
SizeGripMode = 1<<6,
All = TitleAlignment|DrawSeparator|TitleOutline|FrameBorder|BlendColor|SizeGripMode
};
//! constructor
NitrogenException( NitrogenConfiguration configuration = NitrogenConfiguration() ):
NitrogenConfiguration( configuration ),
@ -80,14 +80,14 @@ namespace Nitrogen
//! constructor
NitrogenException( KConfigGroup );
//! destructor
virtual ~NitrogenException( void )
{}
//! equal to operator
bool operator == (const NitrogenException& exception ) const
{
{
return
enabled() == exception.enabled() &&
type() == exception.type() &&
@ -98,85 +98,85 @@ namespace Nitrogen
//! less than operator
bool operator < (const NitrogenException& exception ) const
{
{
if( enabled() != exception.enabled() ) return enabled() < exception.enabled();
else if( mask() != exception.mask() ) return mask() < exception.mask();
else if( type() != exception.type() ) return type() < exception.type();
else return regExp().pattern() < exception.regExp().pattern();
else return regExp().pattern() < exception.regExp().pattern();
}
//! write to kconfig group
virtual void write( KConfigGroup& ) const;
//!@name enability
//@{
bool enabled( void ) const
{ return enabled_; }
void setEnabled( bool enabled )
void setEnabled( bool enabled )
{ enabled_ = enabled; }
//@}
//!@name exception type
//@{
static QString typeName( Type );
static Type type( const QString& name );
virtual QString typeName( void ) const
{ return typeName( type() ); }
virtual Type type( void ) const
{ return type_; }
virtual void setType( Type value )
{ type_ = value; }
//@}
//!@name regular expression
//@{
virtual QRegExp regExp( void ) const
{ return reg_exp_; }
virtual QRegExp& regExp( void )
virtual QRegExp& regExp( void )
{ return reg_exp_; }
//@}
//! mask
//!@{
unsigned int mask( void ) const
{ return mask_; }
void setMask( unsigned int mask )
{ mask_ = mask; }
//@}
private:
//! enability
bool enabled_;
//! exception type
Type type_;
//! regular expression to match window caption
QRegExp reg_exp_;
//! attributes mask
unsigned int mask_;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptionlist.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QTextStream>
@ -29,23 +29,23 @@
namespace Nitrogen
{
//______________________________________________________________
void NitrogenExceptionList::read( const KConfig& config )
{
clear();
for( int index = 0; true; index++ )
{
{
KConfigGroup group( &config, exceptionGroupName( index ) );
if( group.exists() )
if( group.exists() )
{
NitrogenException exception( group );
NitrogenException exception( group );
if( exception.regExp().isValid() ) push_back( exception );
} else break;
}
}
@ -53,7 +53,7 @@ namespace Nitrogen
//______________________________________________________________
void NitrogenExceptionList::write( KConfig& config )
{
// remove previous group
for( int index = 0; true ;index++ )
{
@ -61,26 +61,26 @@ namespace Nitrogen
if( group.exists() ) group.deleteGroup();
else break;
}
// also add exceptions
int index(0);
for( NitrogenExceptionList::const_iterator iter = constBegin(); iter != constEnd(); iter++, index++ )
{
KConfigGroup group( &config, exceptionGroupName( index ) );
iter->write( group );
}
}
//______________________________________________________________
NitrogenExceptionList NitrogenExceptionList::defaultList( void )
{
NitrogenExceptionList out;
// default exception that covers most commonly used gtk based applications
NitrogenException exception;
exception.setType( NitrogenException::WindowClassName );
@ -88,12 +88,12 @@ namespace Nitrogen
exception.setBlendColor( NitrogenException::NoBlending );
exception.setMask( NitrogenException::BlendColor );
exception.setEnabled( true );
out.push_back( exception );
return out;
}
//_______________________________________________________________________
QString NitrogenExceptionList::exceptionGroupName( int index )
{
@ -101,6 +101,6 @@ namespace Nitrogen
QTextStream( &out ) << "Windeco Exception " << index;
return out;
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogenexceptionlist.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <KConfig>
@ -33,35 +33,35 @@
namespace Nitrogen
{
//! nitrogen exceptions list
class NitrogenExceptionList: public QList<NitrogenException>
{
public:
//! default constructor
NitrogenExceptionList( void )
{}
//! default constructor
NitrogenExceptionList( const KConfig& config )
{ read( config ); }
//! read from KConfig
void read( const KConfig& );
//! write to kconfig
void write( KConfig& );
//! default exception list
static NitrogenExceptionList defaultList( void );
//! generate exception group name for given exception index
static QString exceptionGroupName( int index );
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogensizegrip.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,7 +20,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <cassert>
@ -40,36 +40,36 @@
namespace Nitrogen
{
//_____________________________________________
NitrogenSizeGrip::NitrogenSizeGrip( NitrogenClient* client ):
QWidget( client->widget() ),
client_( client ),
decoration_offset_( false )
{
{
setAttribute(Qt::WA_NoSystemBackground );
setAutoFillBackground( false );
// cursor
setCursor( Qt::SizeFDiagCursor );
// size
setFixedSize( QSize( GRIP_SIZE, GRIP_SIZE ) );
// mask
QPolygon p;
p << QPoint( 0, GRIP_SIZE )
<< QPoint( GRIP_SIZE, 0 )
<< QPoint( GRIP_SIZE, GRIP_SIZE )
<< QPoint( 0, GRIP_SIZE );
setMask( QRegion( p ) );
// embed
embed();
updatePosition();
// event filter
client->widget()->installEventFilter( this );
@ -80,18 +80,18 @@ namespace Nitrogen
//_____________________________________________
NitrogenSizeGrip::~NitrogenSizeGrip( void )
{}
//_____________________________________________
void NitrogenSizeGrip::activeChange( void )
{ XMapRaised( QX11Info::display(), winId() ); }
//_____________________________________________
void NitrogenSizeGrip::embed( void )
{
WId window_id = client().windowId();
assert( window_id );
WId current = window_id;
while( true )
{
@ -102,41 +102,41 @@ namespace Nitrogen
if( parent && parent != root && parent != current ) current = parent;
else break;
}
// if the current window is the window_id
// (i.e. if the client is top-level)
// if the current window is the window_id
// (i.e. if the client is top-level)
// the decoration_offset_ flag is set to true, meaning that decoration borders
// are taken into account when placing the widget.
decoration_offset_ = ( current == window_id );
// reparent
XReparentWindow( QX11Info::display(), winId(), current, 0, 0 );
}
//_____________________________________________
bool NitrogenSizeGrip::eventFilter( QObject* object, QEvent* event )
{
if( object != client().widget() ) return false;
if ( event->type() == QEvent::Resize) updatePosition();
return false;
}
//_____________________________________________
void NitrogenSizeGrip::paintEvent( QPaintEvent* )
{
// get relevant colors
QColor base( palette().brush( (client().isActive() ) ? QPalette::Active : QPalette::Inactive, QPalette::Button ).color() );
QColor base( palette().brush( (client().isActive() ) ? QPalette::Active : QPalette::Inactive, QPalette::Button ).color() );
QColor dark( base.darker(250) );
QColor light( base.darker(150) );
// create and configure painter
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing );
painter.setPen( Qt::NoPen );
painter.setBrush( base );
@ -147,100 +147,100 @@ namespace Nitrogen
<< QPoint( GRIP_SIZE, GRIP_SIZE )
<< QPoint( 0, GRIP_SIZE );
painter.drawPolygon( p );
// diagonal border
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( dark, 3 ) );
painter.drawLine( QPoint( 0, GRIP_SIZE ), QPoint( GRIP_SIZE, 0 ) );
// side borders
painter.setPen( QPen( light, 1.5 ) );
painter.drawLine( QPoint( 1, GRIP_SIZE ), QPoint( GRIP_SIZE, GRIP_SIZE ) );
painter.drawLine( QPoint( GRIP_SIZE, 1 ), QPoint( GRIP_SIZE, GRIP_SIZE ) );
painter.end();
}
//_____________________________________________
void NitrogenSizeGrip::mousePressEvent( QMouseEvent* event )
{
switch (event->button())
{
case Qt::RightButton:
{
hide();
hide();
QTimer::singleShot(5000, this, SLOT(show()));
break;
}
case Qt::MidButton:
{
hide();
break;
}
case Qt::LeftButton:
if( rect().contains( event->pos() ) )
{
// check client window id
if( !client().windowId() ) break;
// get matching screen
int screen( client().widget()->x11Info().screen() );
client().widget()->setFocus();
// post event
X11Util::get().moveResizeWidget( client().windowId(), screen, event->globalPos(), X11Util::_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT );
}
break;
default: break;
}
return;
}
//_______________________________________________________________________________
void NitrogenSizeGrip::updatePosition( void )
{
QPoint position(
QPoint position(
client().width() - GRIP_SIZE - OFFSET,
client().height() - GRIP_SIZE - OFFSET );
if( client().isPreview() )
{
position -= QPoint(
position -= QPoint(
client().layoutMetric( NitrogenClient::LM_BorderRight )+
client().layoutMetric( NitrogenClient::LM_OuterPaddingRight ),
client().layoutMetric( NitrogenClient::LM_OuterPaddingBottom )+
client().layoutMetric( NitrogenClient::LM_BorderBottom )
client().layoutMetric( NitrogenClient::LM_BorderBottom )
);
} else if( decoration_offset_ ) {
// not sure whether this case still happens or not
position -= QPoint(
position -= QPoint(
client().layoutMetric( NitrogenClient::LM_BorderLeft )+client().layoutMetric( NitrogenClient::LM_BorderRight ),
client().layoutMetric( NitrogenClient::LM_TitleHeight )+client().layoutMetric( NitrogenClient::LM_TitleEdgeTop )+client().layoutMetric( NitrogenClient::LM_TitleEdgeBottom )+client().layoutMetric( NitrogenClient::LM_BorderBottom ) );
} else {
position -= QPoint(
position -= QPoint(
client().layoutMetric( NitrogenClient::LM_BorderRight ),
client().layoutMetric( NitrogenClient::LM_BorderBottom ) );
}
move( position );
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// nitrogensizegrip.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QWidget>
@ -39,65 +39,65 @@ namespace Nitrogen
//! implements size grip for all widgets
class NitrogenSizeGrip: public QWidget
{
public:
public:
//! constructor
NitrogenSizeGrip( NitrogenClient* );
//! constructor
virtual ~NitrogenSizeGrip( void );
//! event filter
virtual bool eventFilter( QObject*, QEvent* );
public slots:
//! update background color
void activeChange( void );
protected slots:
//! embed into parent widget
void embed( void );
protected:
//!@name event handlers
//@{
//! paint
virtual void paintEvent( QPaintEvent* );
//! mouse press
virtual void mousePressEvent( QMouseEvent* );
//@}
//! client
NitrogenClient& client( void ) const
{ return *client_; }
//! update position
void updatePosition( void );
private:
//! grip size
enum {
enum {
OFFSET = 0,
GRIP_SIZE = 14
GRIP_SIZE = 14
};
// nitrogen client
NitrogenClient* client_;
//! true when decoration offset must be accounted for when moving the widget
bool decoration_offset_;
};
}
#endif

View file

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////
// x11util.cpp
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,97 +20,97 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include "x11util.h"
using namespace std;
namespace Nitrogen
{
//________________________________________________________________________
X11Util& X11Util::get( void )
{
static X11Util singleton;
return singleton;
}
//________________________________________________________________________
X11Util::X11Util( void )
{
{
_initializeAtomNames();
}
//________________________________________________________________________
bool X11Util::isSupported( const Atoms& atom )
{
#ifdef Q_WS_X11
SupportedAtomMap::const_iterator iter( _supportedAtoms().find( atom ) );
if( iter != _supportedAtoms().end() ) return iter->second;
Display* display( QX11Info::display() );
Atom net_supported( findAtom( _NET_SUPPORTED ) );
Atom searched( findAtom( atom ) );
Atom actual;
int format;
unsigned char *data;
unsigned long offset = 0;
while( 1 )
{
unsigned long n, left;
XGetWindowProperty( display, QX11Info::appRootWindow(),
net_supported, offset, 1L,
false, XA_ATOM, &actual,
&format, &n, &left,
false, XA_ATOM, &actual,
&format, &n, &left,
(unsigned char **) &data);
if( data == None ) break;
if( data == None ) break;
// try cast data to atom
Atom found( *(Atom*)data );
if( found == searched )
if( found == searched )
{
supported_atoms_[atom] = true;
return true;
}
if( !left ) break;
else offset ++;
}
supported_atoms_[atom] = false;
#endif
return false;
}
//________________________________________________________________________
bool X11Util::moveResizeWidget(
WId id,
bool X11Util::moveResizeWidget(
WId id,
int screen,
QPoint position,
X11Util::Direction direction,
QPoint position,
X11Util::Direction direction,
Qt::MouseButton button )
{
#ifdef Q_WS_X11
// check
if( !isSupported( _NET_WM_MOVERESIZE ) ) return false;
Display* display( QX11Info::display() );
Atom net_wm_moveresize( findAtom( _NET_WM_MOVERESIZE ) );
Atom net_wm_moveresize( findAtom( _NET_WM_MOVERESIZE ) );
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.message_type = net_wm_moveresize;
@ -119,48 +119,48 @@ namespace Nitrogen
event.xclient.format = 32;
event.xclient.data.l[0] = position.x();
event.xclient.data.l[1] = position.y();
event.xclient.data.l[2] = direction;
event.xclient.data.l[2] = direction;
event.xclient.data.l[3] = button;
event.xclient.data.l[4] = 0;
XUngrabPointer( display, QX11Info::appTime() );
XSendEvent(display,
QX11Info::appRootWindow( screen ),
XSendEvent(display,
QX11Info::appRootWindow( screen ),
false,
SubstructureRedirectMask | SubstructureNotifyMask, &event);
return true;
#else
return false;
#endif
}
//________________________________________________________________________
void X11Util::_initializeAtomNames( void )
{
atom_names_[_NET_SUPPORTED] = "_NET_SUPPORTED";
atom_names_[_NET_WM_STATE] = "_NET_WM_STATE";
atom_names_[_NET_WM_MOVERESIZE] = "_NET_WM_MOVERESIZE";
return;
}
#ifdef Q_WS_X11
//________________________________________________________________________
Atom X11Util::findAtom( const Atoms& atom )
{
// find atom in map
AtomMap::iterator iter( _atoms().find( atom ) );
if( iter != _atoms().end() ) return iter->second;
// create atom if not found
Display* display( QX11Info::display() );
Atom out( XInternAtom(display, qPrintable( atom_names_[atom] ), false ) );
atoms_[atom] = out;
return out;
}
}

View file

@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
// x11util.h
// -------------------
//
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////
#include <QWidget>
@ -36,16 +36,16 @@
#include <X11/Xutil.h>
#endif
namespace Nitrogen
namespace Nitrogen
{
class X11Util
{
public:
//! singleton
static X11Util& get( void );
//! Atoms enumeration
enum Atoms
{
@ -53,7 +53,7 @@ namespace Nitrogen
_NET_WM_STATE,
_NET_WM_MOVERESIZE
};
enum Direction
{
_NET_WM_MOVERESIZE_SIZE_TOPLEFT=0,
@ -66,66 +66,66 @@ namespace Nitrogen
_NET_WM_MOVERESIZE_SIZE_LEFT=7,
_NET_WM_MOVERESIZE_MOVE=8,
_NET_WM_MOVERESIZE_SIZE_KEYBOARD=9,
_NET_WM_MOVERESIZE_MOVE_KEYBOARD=10
_NET_WM_MOVERESIZE_MOVE_KEYBOARD=10
};
//! supported atoms
bool isSupported( const Atoms& atom );
//! move/resize widget using X11 window manager
/*! returns true on success */
bool moveResizeWidget( WId, int screen, QPoint, Direction, Qt::MouseButton button = Qt::LeftButton );
#ifdef Q_WS_X11
//! find atom
Atom findAtom( const Atoms& atom );
#endif
private:
//! constructor
X11Util( void );
//! atom names
typedef std::map<Atoms, QString> AtomNameMap;
typedef std::map<Atoms, QString> AtomNameMap;
//! atom names
void _initializeAtomNames( void );
//! atom names
const AtomNameMap& _atomNames( void ) const
{ return atom_names_; }
AtomNameMap atom_names_;
//! supported atoms
typedef std::map<Atoms, bool > SupportedAtomMap;
//! supported atoms
const SupportedAtomMap& _supportedAtoms( void ) const
{ return supported_atoms_; }
SupportedAtomMap supported_atoms_;
#ifdef Q_WS_X11
//! atom map
typedef std::map<Atoms, Atom> AtomMap;
//! atoms
// const AtomMap& _atoms( void ) const
AtomMap& _atoms( void )
{ return atoms_; }
//! atoms
AtomMap atoms_;
#endif
};
}
#endif