From af15bebbdd04d7037a996e3df0c9755ef5acad3c Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 9 Sep 2009 00:55:55 +0000 Subject: [PATCH] mass whitespace cleanup svn path=/trunk/KDE/kdebase/workspace/; revision=1021371 --- clients/nitrogen/CMakeLists.txt | 14 +- clients/nitrogen/config/CMakeLists.txt | 8 +- clients/nitrogen/config/config.cpp | 116 ++-- clients/nitrogen/config/config.h | 42 +- clients/nitrogen/config/itemmodel.cpp | 20 +- clients/nitrogen/config/itemmodel.h | 52 +- clients/nitrogen/config/listmodel.h | 210 +++---- .../config/nitrogenconfigurationui.cpp | 70 +-- .../nitrogen/config/nitrogenconfigurationui.h | 24 +- .../config/nitrogenexceptiondialog.cpp | 62 +- .../nitrogen/config/nitrogenexceptiondialog.h | 50 +- .../config/nitrogenexceptionlistwidget.cpp | 168 +++--- .../config/nitrogenexceptionlistwidget.h | 72 +-- .../config/nitrogenexceptionmodel.cpp | 52 +- .../nitrogen/config/nitrogenexceptionmodel.h | 38 +- clients/nitrogen/nitrogen.cpp | 124 ++-- clients/nitrogen/nitrogen.h | 68 +-- clients/nitrogen/nitrogenbutton.cpp | 150 ++--- clients/nitrogen/nitrogenbutton.h | 54 +- clients/nitrogen/nitrogenclient.cpp | 568 +++++++++--------- clients/nitrogen/nitrogenclient.h | 114 ++-- clients/nitrogen/nitrogenconfiguration.cpp | 98 +-- clients/nitrogen/nitrogenconfiguration.h | 106 ++-- clients/nitrogen/nitrogenexception.cpp | 36 +- clients/nitrogen/nitrogenexception.h | 78 +-- clients/nitrogen/nitrogenexceptionlist.cpp | 42 +- clients/nitrogen/nitrogenexceptionlist.h | 22 +- clients/nitrogen/nitrogensizegrip.cpp | 114 ++-- clients/nitrogen/nitrogensizegrip.h | 50 +- clients/nitrogen/x11util.cpp | 94 +-- clients/nitrogen/x11util.h | 60 +- 31 files changed, 1388 insertions(+), 1388 deletions(-) diff --git a/clients/nitrogen/CMakeLists.txt b/clients/nitrogen/CMakeLists.txt index a9618e58a3..02ada7a517 100644 --- a/clients/nitrogen/CMakeLists.txt +++ b/clients/nitrogen/CMakeLists.txt @@ -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 ) diff --git a/clients/nitrogen/config/CMakeLists.txt b/clients/nitrogen/config/CMakeLists.txt index 7e60c3ffef..c14aba53d7 100644 --- a/clients/nitrogen/config/CMakeLists.txt +++ b/clients/nitrogen/config/CMakeLists.txt @@ -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} ) diff --git a/clients/nitrogen/config/config.cpp b/clients/nitrogen/config/config.cpp index a570e0a8f9..aa70da0c9e 100644 --- a/clients/nitrogen/config/config.cpp +++ b/clients/nitrogen/config/config.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // config.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (C) 2008 Lubos Lunak // @@ -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 @@ -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(); - - + + } -} +} diff --git a/clients/nitrogen/config/config.h b/clients/nitrogen/config/config.h index b1c3674734..4321eae735 100644 --- a/clients/nitrogen/config/config.h +++ b/clients/nitrogen/config/config.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // config.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (C) 2008 Lubos Lunak // @@ -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 @@ -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 diff --git a/clients/nitrogen/config/itemmodel.cpp b/clients/nitrogen/config/itemmodel.cpp index 2ea0561be8..2ae01d3a65 100644 --- a/clients/nitrogen/config/itemmodel.cpp +++ b/clients/nitrogen/config/itemmodel.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // itemmodel.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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; - + } diff --git a/clients/nitrogen/config/itemmodel.h b/clients/nitrogen/config/itemmodel.h index dd4ba48227..4cb543925f 100644 --- a/clients/nitrogen/config/itemmodel.h +++ b/clients/nitrogen/config/itemmodel.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // itemmodel.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 diff --git a/clients/nitrogen/config/listmodel.h b/clients/nitrogen/config/listmodel.h index c55e0c500c..5e675f0248 100644 --- a/clients/nitrogen/config/listmodel.h +++ b/clients/nitrogen/config/listmodel.h @@ -3,7 +3,7 @@ ////////////////////////////////////////////////////////////////////////////// // listmodel.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -35,12 +35,12 @@ //! Job model. Stores job information for display in lists template class ListModel : public ItemModel { - + public: - + //! value type typedef T ValueType; - + //! reference typedef T& Reference; @@ -49,7 +49,7 @@ template class ListModel : public ItemModel //! list of vector typedef std::vector List; - + //! list of vector typedef std::set Set; @@ -57,217 +57,217 @@ template 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 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 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 diff --git a/clients/nitrogen/config/nitrogenconfigurationui.cpp b/clients/nitrogen/config/nitrogenconfigurationui.cpp index a2dd488303..a1d915d259 100644 --- a/clients/nitrogen/config/nitrogenconfigurationui.cpp +++ b/clients/nitrogen/config/nitrogenconfigurationui.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenconfigurationui.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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); + } - + } diff --git a/clients/nitrogen/config/nitrogenconfigurationui.h b/clients/nitrogen/config/nitrogenconfigurationui.h index 2f68cdd536..a804122cbc 100644 --- a/clients/nitrogen/config/nitrogenconfigurationui.h +++ b/clients/nitrogen/config/nitrogenconfigurationui.h @@ -3,7 +3,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenconfigurationui.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 diff --git a/clients/nitrogen/config/nitrogenexceptiondialog.cpp b/clients/nitrogen/config/nitrogenexceptiondialog.cpp index 0eaa156179..7e64e9a0c0 100644 --- a/clients/nitrogen/config/nitrogenexceptiondialog.cpp +++ b/clients/nitrogen/config/nitrogenexceptiondialog.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptiondialog.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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; } - + } diff --git a/clients/nitrogen/config/nitrogenexceptiondialog.h b/clients/nitrogen/config/nitrogenexceptiondialog.h index f39f6b3e04..1a62427be8 100644 --- a/clients/nitrogen/config/nitrogenexceptiondialog.h +++ b/clients/nitrogen/config/nitrogenexceptiondialog.h @@ -3,7 +3,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptiondialog.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 diff --git a/clients/nitrogen/config/nitrogenexceptionlistwidget.cpp b/clients/nitrogen/config/nitrogenexceptionlistwidget.cpp index d1c066e934..b7f7bf16d3 100644 --- a/clients/nitrogen/config/nitrogenexceptionlistwidget.cpp +++ b/clients/nitrogen/config/nitrogenexceptionlistwidget.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // NitrogenExceptionListWidget.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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; } - + } diff --git a/clients/nitrogen/config/nitrogenexceptionlistwidget.h b/clients/nitrogen/config/nitrogenexceptionlistwidget.h index a27e978253..0fdefd7a72 100644 --- a/clients/nitrogen/config/nitrogenexceptionlistwidget.h +++ b/clients/nitrogen/config/nitrogenexceptionlistwidget.h @@ -3,7 +3,7 @@ ////////////////////////////////////////////////////////////////////////////// // NitrogenExceptionListWidget.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 - + diff --git a/clients/nitrogen/config/nitrogenexceptionmodel.cpp b/clients/nitrogen/config/nitrogenexceptionmodel.cpp index ec3c68993f..3d20c89dfe 100644 --- a/clients/nitrogen/config/nitrogenexceptionmodel.cpp +++ b/clients/nitrogen/config/nitrogenexceptionmodel.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptionmodel.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 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(); + } - + } diff --git a/clients/nitrogen/config/nitrogenexceptionmodel.h b/clients/nitrogen/config/nitrogenexceptionmodel.h index 2dc0365324..8b721eafc7 100644 --- a/clients/nitrogen/config/nitrogenexceptionmodel.h +++ b/clients/nitrogen/config/nitrogenexceptionmodel.h @@ -3,7 +3,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptionmodel.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 { - + 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 - + diff --git a/clients/nitrogen/nitrogen.cpp b/clients/nitrogen/nitrogen.cpp index 1ca868cb36..91e2ec117c 100644 --- a/clients/nitrogen/nitrogen.cpp +++ b/clients/nitrogen/nitrogen.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogen.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (c) 2006, 2007 Riccardo Iaconelli // @@ -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 @@ -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 diff --git a/clients/nitrogen/nitrogen.h b/clients/nitrogen/nitrogen.h index ab8bb2ab47..ad14c56cff 100644 --- a/clients/nitrogen/nitrogen.h +++ b/clients/nitrogen/nitrogen.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogen.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira // Copyright (c) 2006, 2007 Riccardo Iaconelli // @@ -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 @@ -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 diff --git a/clients/nitrogen/nitrogenbutton.cpp b/clients/nitrogen/nitrogenbutton.cpp index 682377fd2b..190782607d 100644 --- a/clients/nitrogen/nitrogenbutton.cpp +++ b/clients/nitrogen/nitrogenbutton.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenbutton.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (c) 2006, 2007 Riccardo Iaconelli // Copyright (c) 2006, 2007 Casper Boemann @@ -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 @@ -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; } - -} + +} diff --git a/clients/nitrogen/nitrogenbutton.h b/clients/nitrogen/nitrogenbutton.h index 125c8d76bf..339803fc7f 100644 --- a/clients/nitrogen/nitrogenbutton.h +++ b/clients/nitrogen/nitrogenbutton.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenbutton.h // ------------------- -// +// // Copyright (c) 2006, 2007 Riccardo Iaconelli // Copyright (c) 2006, 2007 Casper Boemann // Copyright (c) 2009 Hugo Pereira Da Costa @@ -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 diff --git a/clients/nitrogen/nitrogenclient.cpp b/clients/nitrogen/nitrogenclient.cpp index 835c3a9a32..bc71bf5b5d 100644 --- a/clients/nitrogen/nitrogenclient.cpp +++ b/clients/nitrogen/nitrogenclient.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenclient.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (c) 2006, 2007 Casper Boemann // Copyright (c) 2006, 2007 Riccardo Iaconelli @@ -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 @@ -49,29 +49,29 @@ using namespace std; namespace Nitrogen { - + K_GLOBAL_STATIC_WITH_ARGS(OxygenHelper, globalHelper, ("nitrogenDeco")) - + //___________________________________________ OxygenHelper *nitrogenHelper() { return globalHelper; } - + //___________________________________________ static void oxkwincleanupBefore() { OxygenHelper *h = globalHelper; h->invalidateCaches(); } - + //___________________________________________ void renderDot(QPainter *p, const QPointF &point, qreal diameter) { p->drawEllipse(QRectF(point.x()-diameter/2, point.y()-diameter/2, diameter, diameter)); } - + //___________________________________________ - NitrogenClient::NitrogenClient(KDecorationBridge *b, KDecorationFactory *f): - KCommonDecorationUnstable(b, f), + NitrogenClient::NitrogenClient(KDecorationBridge *b, KDecorationFactory *f): + KCommonDecorationUnstable(b, f), colorCacheInvalid_(true), size_grip_( 0 ), shadowTiles_( 0 ), @@ -79,84 +79,84 @@ namespace Nitrogen helper_(*globalHelper), initialized_( false ) { qAddPostRoutine(oxkwincleanupBefore); } - + //___________________________________________ NitrogenClient::~NitrogenClient() { - + // delete sizegrip if any if( hasSizeGrip() ) deleteSizeGrip(); - + // delete tilesets - if( shadowTiles_ ) delete shadowTiles_; + if( shadowTiles_ ) delete shadowTiles_; if( glowTiles_ ) delete glowTiles_; - + } - + //___________________________________________ QString NitrogenClient::visibleName() const { return i18n("Nitrogen"); } - + //___________________________________________ void NitrogenClient::init() { - + KCommonDecoration::init(); widget()->setAttribute(Qt::WA_NoSystemBackground ); widget()->setAutoFillBackground( false ); initialized_ = true; - + // in case of preview, one wants to make the label used // for the central widget transparent. This allows one to have // the correct background (with gradient) rendered - // Remark: this is minor (and safe) a hack. + // Remark: this is minor (and safe) a hack. // This should be moved upstream (into kwin/lib/kdecoration) - if( isPreview() ) - { - + if( isPreview() ) + { + QList children( widget()->findChildren() ); for( QList::iterator iter = children.begin(); iter != children.end(); iter++ ) { (*iter)->setAutoFillBackground( false ); } - + } - + resetConfiguration(); - + } - + //___________________________________________ bool NitrogenClient::isMaximized() const { return maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows(); } - + //___________________________________________ bool NitrogenClient::decorationBehaviour(DecorationBehaviour behaviour) const { - switch (behaviour) + switch (behaviour) { - + case DB_MenuClose: return true; - + case DB_WindowMask: return false; - + default: return KCommonDecoration::decorationBehaviour(behaviour); } } - + //___________________________________________ int NitrogenClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const { - + bool maximized( isMaximized() ); int frameBorder( configuration().frameBorder() ); - + // used to increase hit area on the sides of the widget int extraBorder = (maximized && compositingActive()) ? 0 : EXTENDED_HITAREA; int buttonSize( configuration().buttonSize() ); - - switch (lm) + + switch (lm) { case LM_BorderLeft: case LM_BorderRight: @@ -168,50 +168,50 @@ namespace Nitrogen } else if( configuration().frameBorder() == NitrogenConfiguration::BorderNone && isPreview() && !compositingActive() ) { border = 1; } else if( lm == LM_BorderBottom && frameBorder >= NitrogenConfiguration::BorderTiny ) { - - // for tiny border, the convention is to have a larger bottom area in order to + + // for tiny border, the convention is to have a larger bottom area in order to // make resizing easier border = qMax(frameBorder, 4); - + } else { - - border = frameBorder; - + + border = frameBorder; + } - + return border + extraBorder; } - + case LM_TitleEdgeTop: { int border = 0; - if( !( respectWindowState && maximized )) - { - border = TFRAMESIZE; + if( !( respectWindowState && maximized )) + { + border = TFRAMESIZE; if( configuration().drawTitleOutline() ) border += HFRAMESIZE/2; } - + return border + extraBorder; - + } - + case LM_TitleEdgeBottom: { if( configuration().drawTitleOutline() ) return HFRAMESIZE/2; else return 0; } - + case LM_TitleEdgeLeft: case LM_TitleEdgeRight: { int border = 0; - if( !(respectWindowState && maximized) ) + if( !(respectWindowState && maximized) ) { border = 6; } - + return border + extraBorder; - + } - + case LM_TitleBorderLeft: case LM_TitleBorderRight: { @@ -219,240 +219,240 @@ namespace Nitrogen if( configuration().drawTitleOutline() ) border += 2*HFRAMESIZE; return border; } - + case LM_ButtonWidth: case LM_ButtonHeight: case LM_TitleHeight: { if (respectWindowState && isToolWindow()) { - + return buttonSize; - + } else { - + return buttonSize; - + } } - + case LM_ButtonSpacing: return 1; - + case LM_ButtonMarginTop: return 0; - + // outer margin for shadow/glow case LM_OuterPaddingLeft: case LM_OuterPaddingRight: case LM_OuterPaddingTop: case LM_OuterPaddingBottom: return SHADOW_WIDTH - extraBorder; - + default: return KCommonDecoration::layoutMetric(lm, respectWindowState, btn); } - + } - + //_________________________________________________________ KCommonDecorationButton *NitrogenClient::createButton(::ButtonType type) { switch (type) { case MenuButton: return new NitrogenButton(*this, i18n("Menu"), ButtonMenu); - + case HelpButton: return new NitrogenButton(*this, i18n("Help"), ButtonHelp); - + case MinButton: return new NitrogenButton(*this, i18n("Minimize"), ButtonMin); - + case MaxButton: return new NitrogenButton(*this, i18n("Maximize"), ButtonMax); - + case CloseButton: return new NitrogenButton(*this, i18n("Close"), ButtonClose); - + case AboveButton: return new NitrogenButton(*this, i18n("Keep Above Others"), ButtonAbove); - + case BelowButton: return new NitrogenButton(*this, i18n("Keep Below Others"), ButtonBelow); - + case OnAllDesktopsButton: return new NitrogenButton(*this, i18n("On All Desktops"), ButtonSticky); - + case ShadeButton: return new NitrogenButton(*this, i18n("Shade Button"), ButtonShade); - + default: return 0; } } - + //_________________________________________________________ QColor reduceContrast(const QColor &c0, const QColor &c1, double t) { double s = KColorUtils::contrastRatio(c0, c1); if (s < t) return c1; - + double l = 0.0, h = 1.0; double x = s, a; QColor r = c1; - for (int maxiter = 16; maxiter; --maxiter) + for (int maxiter = 16; maxiter; --maxiter) { - + a = 0.5 * (l + h); r = KColorUtils::mix(c0, c1, a); x = KColorUtils::contrastRatio(c0, r); - + if (fabs(x - t) < 0.01) break; if (x > t) h = a; else l = a; } - + return r; } - + //_________________________________________________________ QRegion NitrogenClient::calcMask( void ) const { - - if( isMaximized() ) + + if( isMaximized() ) { return widget()->rect(); } - + QRect frame( widget()->rect() ); - + // dimensions int w=frame.width(); int h=frame.height(); - + // multipliers int left = 1; int right = 1; int top = 1; int bottom = 1; - + // disable bottom corners when border frame is too small and window is not shaded if( configuration().frameBorder() < NitrogenConfiguration::BorderTiny && !isShade() ) bottom = 0; - + int sw = layoutMetric( LM_OuterPaddingLeft ); int sh = layoutMetric( LM_OuterPaddingTop ); w -= sw + layoutMetric( LM_OuterPaddingRight ); h -= sh + layoutMetric( LM_OuterPaddingBottom ); - - + + QRegion mask(sw + 4*left, sh + 0*top, w-4*(left+right), h-0*(top+bottom)); mask += QRegion(sw + 0*left, sh + 4*top, w-0*(left+right), h-4*(top+bottom)); mask += QRegion(sw + 2*left, sh + 1*top, w-2*(left+right), h-1*(top+bottom)); - mask += QRegion(sw + 1*left, sh + 2*top, w-1*(left+right), h-2*(top+bottom)); - + mask += QRegion(sw + 1*left, sh + 2*top, w-1*(left+right), h-2*(top+bottom)); + return mask; - + } - + //_________________________________________________________ QColor NitrogenClient::titlebarTextColor(const QPalette &palette) { - - if( configuration().drawTitleOutline() ) - { - - return options()->color(ColorFont, isActive()); - + + if( configuration().drawTitleOutline() ) + { + + return options()->color(ColorFont, isActive()); + } else if (isActive()) { - + return palette.color(QPalette::Active, QPalette::WindowText); - + } else { - - if(colorCacheInvalid_) + + if(colorCacheInvalid_) { - + QColor ab = palette.color(QPalette::Active, QPalette::Window); QColor af = palette.color(QPalette::Active, QPalette::WindowText); QColor nb = palette.color(QPalette::Inactive, QPalette::Window); QColor nf = palette.color(QPalette::Inactive, QPalette::WindowText); - + colorCacheInvalid_ = false; cachedTitlebarTextColor_ = reduceContrast(nb, nf, qMax(qreal(2.5), KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4)))); } - + return cachedTitlebarTextColor_; - + } - + } - + //_________________________________________________________ void NitrogenClient::renderWindowBackground( QPainter* painter, const QRect& rect, const QWidget* widget, const QPalette& palette ) const { - - if( configuration().blendColor() == NitrogenConfiguration::NoBlending ) - { - + + if( configuration().blendColor() == NitrogenConfiguration::NoBlending ) + { + painter->fillRect( rect, palette.color( widget->window()->backgroundRole() ) ); - - } else { - + + } else { + int offset = layoutMetric( LM_OuterPaddingTop ); int height = 64 + configuration().buttonSize() - 22; const QWidget* window( isPreview() ? NitrogenClient::widget() : widget->window() ); helper().renderWindowBackground(painter, rect, widget, window, palette, offset, height ); - - } - + + } + } - + //_________________________________________________________ void NitrogenClient::renderWindowBorder( QPainter* painter, const QRect& clipRect, const QWidget* widget, const QPalette& palette ) const { - + const QWidget* window = (isPreview()) ? NitrogenClient::widget() : widget->window(); - + // get coordinates relative to the client area // this is annoying. One could use mapTo if this was taking const QWidget* and not - // const QWidget* as argument. + // const QWidget* as argument. const QWidget* w = widget; QPoint position( 0, 0 ); while ( w != window && !w->isWindow() && w != w->parentWidget() ) { position += w->geometry().topLeft(); w = w->parentWidget(); - } - + } + // save painter if (clipRect.isValid()) { painter->save(); painter->setClipRegion(clipRect,Qt::IntersectClip); } - + painter->setPen( Qt::NoPen ); - + QColor color = palette.color(window->backgroundRole()); QColor top = helper().backgroundTopColor( color ); QColor bottom = helper().backgroundBottomColor( color ); - + QRect r = (isPreview()) ? NitrogenClient::widget()->rect():window->rect(); r.adjust( SHADOW_WIDTH, SHADOW_WIDTH, -SHADOW_WIDTH, -SHADOW_WIDTH ); r.adjust(0,0, 1, 1); - + // draw top line { - + int shadow_size = 5; int height = HFRAMESIZE; QRect rect( r.topLeft()-position, QSize( r.width(), height ) ); helper().slab( palette.color( widget->backgroundRole() ), 0, shadow_size )->render( rect.adjusted(-shadow_size-1, 0, shadow_size+1, 2 ), painter, TileSet::Bottom ); - + int offset = layoutMetric( LM_OuterPaddingTop ); int gradient_height = 64 + configuration().buttonSize() - 22; const QWidget* window( isPreview() ? NitrogenClient::widget() : widget->window() ); helper().renderWindowBackground(painter, rect, widget, window, palette, offset, gradient_height ); - + } - + // draw bottom line if( configuration().frameBorder() >= NitrogenConfiguration::BorderTiny ) { @@ -460,41 +460,41 @@ namespace Nitrogen painter->setBrush( bottom ); painter->drawRect( QRect( r.bottomLeft()-position-QPoint(0,height), QSize( r.width(), height ) ) ); } - + // left and right if( configuration().frameBorder() >= NitrogenConfiguration::BorderTiny ) { - + QLinearGradient gradient(0, r.top(), 0, r.height() ); gradient.setColorAt(0.0, top); gradient.setColorAt(0.5, color); gradient.setColorAt(1.0, bottom); - + painter->setBrush( gradient ); - + // left { int width = qMin( HFRAMESIZE, layoutMetric( LM_BorderLeft ) ); painter->drawRect( QRect( r.topLeft()-position, QSize( width, r.height() ) ) ); } - + // right { int width = qMin( HFRAMESIZE, layoutMetric( LM_BorderRight ) ); painter->drawRect( QRect( r.topRight()-position-QPoint(width,0), QSize( width, r.height() ) ) ); } - + } - + // restore painter if (clipRect.isValid()) painter->restore(); } - + //_________________________________________________________ void NitrogenClient::renderTitleOutline( QPainter* painter, const QRect& rect, const QPalette& palette ) const { - + // shadow { int shadow_size = 7; @@ -502,7 +502,7 @@ namespace Nitrogen if( !isMaximized() ) voffset += HFRAMESIZE; helper().slab( palette.color( widget()->backgroundRole() ), 0, shadow_size )->render( rect.adjusted(0, voffset, 0, 0 ), painter, TileSet::Bottom|TileSet::Left|TileSet::Right ); } - + // center { int offset = layoutMetric( LM_OuterPaddingTop ); @@ -511,107 +511,107 @@ namespace Nitrogen const QWidget* window( isPreview() ? widget() : widget()->window() ); helper().renderWindowBackground(painter, rect.adjusted( 4, voffset, -4, -4 ), widget(), window, palette, offset, height ); } - + } - + //_________________________________________________________ void NitrogenClient::activeChange( void ) { - + // update size grip so that it gets the right color - if( hasSizeGrip() ) + if( hasSizeGrip() ) { sizeGrip().activeChange(); sizeGrip().update(); } - + KCommonDecorationUnstable::activeChange(); - + } //_________________________________________________________ void NitrogenClient::maximizeChange( void ) - { - if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) ); + { + if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) ); KCommonDecorationUnstable::maximizeChange(); } //_________________________________________________________ void NitrogenClient::shadeChange( void ) - { - if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) ); + { + if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) ); KCommonDecorationUnstable::shadeChange(); } //_________________________________________________________ QPalette NitrogenClient::backgroundPalette( const QWidget* widget, QPalette palette ) const - { - + { + if( configuration().drawTitleOutline() && isActive() ) { palette.setColor( widget->window()->backgroundRole(), options()->color( KDecorationDefines::ColorTitleBar, true ) ); } - + return palette; - + } - + //________________________________________________________________ void NitrogenClient::updateWindowShape() - { - + { + if(isMaximized() || compositingActive() ) { - + clearMask(); - + } else { - - setMask( calcMask() ); - + + setMask( calcMask() ); + } - + } - - + + //___________________________________________ void NitrogenClient::resetConfiguration( void ) - { - + { + if( !initialized_ ) return; - - configuration_ = NitrogenFactory::configuration( *this ); - + + configuration_ = NitrogenFactory::configuration( *this ); + // handle size grip - if( configuration_.drawSizeGrip() ) + if( configuration_.drawSizeGrip() ) { - - if( !hasSizeGrip() ) createSizeGrip(); - + + if( !hasSizeGrip() ) createSizeGrip(); + } else if( hasSizeGrip() ) deleteSizeGrip(); - + } - + //_________________________________________________________ void NitrogenClient::paintEvent( QPaintEvent* event ) { - - + + // factory if(!( initialized_ && NitrogenFactory::initialized() ) ) return; - + // palette QPalette palette = widget()->palette(); palette.setCurrentColorGroup( (isActive() ) ? QPalette::Active : QPalette::Inactive ); - + // painter QPainter painter(widget()); painter.setClipRegion( event->region() ); - + // define frame QRect frame = widget()->rect(); - + // base color QColor color = palette.window().color(); - + // draw shadows if( compositingActive() && !isMaximized() ) { @@ -621,60 +621,60 @@ namespace Nitrogen SHADOW_WIDTH, isActive() )->render( frame.adjusted( 4, 4, -4, -4), &painter, TileSet::Ring); } - + // adjust frame frame.adjust( SHADOW_WIDTH, SHADOW_WIDTH, -SHADOW_WIDTH, -SHADOW_WIDTH ); - + // adjust mask if( compositingActive() || isPreview() ) { - + if( isMaximized() ) { - - painter.setClipRect( frame, Qt::IntersectClip ); - + + painter.setClipRect( frame, Qt::IntersectClip ); + } else { - + int x, y, w, h; frame.getRect(&x, &y, &w, &h); - + // multipliers int left = 1; int right = 1; int top = 1; int bottom = 1; - + // disable bottom corners when border frame is too small and window is not shaded if( configuration().frameBorder() == NitrogenConfiguration::BorderNone && !isShade() ) bottom = 0; QRegion mask( x+5*left, y+0*top, w-5*(left+right), h-0*(top+bottom)); mask += QRegion(x+0*left, y+5*top, w-0*(left+right), h-5*(top+bottom)); mask += QRegion(x+2*left, y+2*top, w-2*(left+right), h-2*(top+bottom)); mask += QRegion(x+3*left, y+1*top, w-3*(left+right), h-1*(top+bottom)); - mask += QRegion(x+1*left, y+3*top, w-1*(left+right), h-3*(top+bottom)); + mask += QRegion(x+1*left, y+3*top, w-1*(left+right), h-3*(top+bottom)); if( configuration().frameBorder() == NitrogenConfiguration::BorderNone ) { mask += QRegion(x+0*left, y+4*top, w-0*(left+right), h-4*(top+bottom)); } painter.setClipRegion( mask, Qt::IntersectClip ); - + } - - + + } - + // window background renderWindowBackground( &painter, frame, widget(), palette ); - if( isActive() && configuration().drawTitleOutline() && !isMaximized() ) + if( isActive() && configuration().drawTitleOutline() && !isMaximized() ) { renderWindowBorder( &painter, frame, widget(), backgroundPalette( widget(), palette ) ); } - + // clipping if( compositingActive() ) painter.setClipping(false); - // in preview mode and when frame border is 0, + // in preview mode and when frame border is 0, // one still draw a small rect around, unless kde is recent enough, - // useOxygenShadow is set to true, + // useOxygenShadow is set to true, // and copositing is active // (that makes a lot of ifs) if( isPreview() && configuration().frameBorder() == NitrogenConfiguration::BorderNone && !compositingActive() ) @@ -682,7 +682,7 @@ namespace Nitrogen painter.save(); painter.setBrush( Qt::NoBrush ); painter.setPen( QPen( helper().calcDarkColor( widget()->palette().window().color() ), 1 ) ); - + QPainterPath path; QPoint first( frame.topLeft()+QPoint( 0, 6 ) ); path.moveTo( first ); @@ -695,7 +695,7 @@ namespace Nitrogen painter.drawPath( path ); painter.restore(); } - + int extraBorder = ( isMaximized() && compositingActive() ) ? 0 : EXTENDED_HITAREA; // dimensions @@ -704,19 +704,19 @@ namespace Nitrogen const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); const int marginLeft = layoutMetric(LM_TitleBorderLeft); const int marginRight = layoutMetric(LM_TitleBorderRight); - + const int titleLeft = frame.left() + titleEdgeLeft + buttonsLeftWidth() + marginLeft; const int titleWidth = frame.width() - titleEdgeLeft - layoutMetric(LM_TitleEdgeRight) - buttonsLeftWidth() - buttonsRightWidth() - marginLeft - marginRight; - + QRect titleRect( titleLeft, titleTop-1, titleWidth, titleHeight ); painter.setFont( options()->font(isActive(), false) ); if( isActive() && configuration().drawTitleOutline() ) { - + // get title bounding rect QRect boundingRect = painter.boundingRect( titleRect, configuration().titleAlignment() | Qt::AlignVCenter, caption() ); @@ -725,41 +725,41 @@ namespace Nitrogen boundingRect.setBottom( titleTop+titleHeight ); boundingRect.setLeft( qMax( boundingRect.left(), titleLeft ) - 2*HFRAMESIZE ); boundingRect.setRight( qMin( boundingRect.right(), titleLeft + titleWidth ) + 2*HFRAMESIZE ); - + renderTitleOutline( &painter, boundingRect, backgroundPalette( widget(), palette ) ); - + } - - // draw title text + + // draw title text painter.setPen( titlebarTextColor( backgroundPalette( widget(), palette ) ) ); - + painter.drawText( titleRect, configuration().titleAlignment() | Qt::AlignVCenter, caption() ); painter.setRenderHint(QPainter::Antialiasing); - + // adjust if there are shadows if (compositingActive()) frame.adjust(-1,-1, 1, 1); - + // dimensions int x,y,w,h; frame.getRect(&x, &y, &w, &h); - + // separator - if( drawSeparator() ) + if( drawSeparator() ) { helper().drawSeparator(&painter, QRect(x, titleTop+titleHeight-1.5, w, 2), color, Qt::Horizontal); } - + // shadow and resize handles if( configuration().frameBorder() >= NitrogenConfiguration::BorderTiny && !isMaximized() ) { - + helper().drawFloatFrame( - &painter, frame, backgroundPalette( widget(), palette ).color( widget()->backgroundRole() ), + &painter, frame, backgroundPalette( widget(), palette ).color( widget()->backgroundRole() ), !compositingActive(), isActive(), KDecoration::options()->color(ColorTitleBar) ); if( isResizable() && !isShade() ) - { - + { + // Draw the 3-dots resize handles qreal cenY = h / 2 + x + 0.5; qreal posX = w + y - 2.5; @@ -768,9 +768,9 @@ namespace Nitrogen renderDot(&painter, QPointF(posX, cenY - 3), 1.8); renderDot(&painter, QPointF(posX, cenY), 1.8); renderDot(&painter, QPointF(posX, cenY + 3), 1.8); - + } - + // Draw the 3-dots resize handles if( isResizable() && !isShade() && !configuration().drawSizeGrip() ) { @@ -783,36 +783,36 @@ namespace Nitrogen renderDot(&painter, QPointF(5.5, 5.5), 1.8); renderDot(&painter, QPointF(6.5, 2.5), 1.8); } - + } - + } - + //________________________________________________________________ NitrogenConfiguration NitrogenClient::configuration( void ) const { return configuration_; } - + //_________________________________________________________________ void NitrogenClient::createSizeGrip( void ) { - + assert( !hasSizeGrip() ); if( ( isResizable() && windowId() != 0 ) || isPreview() ) - { - size_grip_ = new NitrogenSizeGrip( this ); + { + size_grip_ = new NitrogenSizeGrip( this ); sizeGrip().setVisible( !( isMaximized() || isShade() ) ); } - + } - + //_________________________________________________________________ void NitrogenClient::deleteSizeGrip( void ) { assert( hasSizeGrip() ); size_grip_->deleteLater(); size_grip_ = 0; - } - + } + //_________________________________________________________________ TileSet *NitrogenClient::shadowTiles(const QColor& color, const QColor& glow, qreal size, bool active) { @@ -821,43 +821,43 @@ namespace Nitrogen opt.width = size; opt.windowColor = color; opt.glowColor = glow; - + ShadowTilesOption currentOpt = active ? glowTilesOption_:shadowTilesOption_; - + bool optionChanged = !(currentOpt == opt ); if (active && glowTiles_ ) - { - + { + if( optionChanged) delete glowTiles_; else return glowTiles_; - + } else if (!active && shadowTiles_ ) { - + if( optionChanged ) delete shadowTiles_; else return shadowTiles_; - + } - + kDebug( 1212 ) << " creating tiles - active: " << active << endl; TileSet *tileSet = 0; - + if( active && configuration().drawTitleOutline() && configuration().frameBorder() == NitrogenConfiguration::BorderNone ) { - + //--------------------------------------------------------------- // Create new glow/shadow tiles QPixmap shadow = QPixmap( size*2, size*2 ); shadow.fill( Qt::transparent ); - + QPainter p( &shadow ); p.setRenderHint( QPainter::Antialiasing ); - + QPixmap shadowTop = shadowPixmap( color, glow, size ); QRect topRect( shadow.rect() ); topRect.setBottom( int( size )-1 ); p.setClipRect( topRect ); p.drawPixmap( QPointF( 0, 0 ), shadowTop ); - + QPixmap shadowBottom = shadowPixmap( widget()->palette().color( widget()->backgroundRole() ), glow, size ); QRect bottomRect( shadow.rect() ); bottomRect.setTop( int( size ) ); @@ -866,50 +866,50 @@ namespace Nitrogen p.end(); tileSet = new TileSet( shadow, size, size, 1, 1); - + } else { - + tileSet = new TileSet( - shadowPixmap( color, glow, size ), + shadowPixmap( color, glow, size ), size, size, 1, 1); - + } - + // store option and style if( active ) { - + glowTilesOption_ = opt; glowTiles_ = tileSet; - + } else { - + shadowTilesOption_ = opt; shadowTiles_ = tileSet; - + } - + return tileSet; } - + QPixmap NitrogenClient::shadowPixmap(const QColor& color, const QColor& glow, qreal size) const { - + //--------------------------------------------------------------- // Create new glow/shadow tiles QPixmap shadow = QPixmap( size*2, size*2 ); shadow.fill( Qt::transparent ); - + QPainter p( &shadow ); p.setRenderHint( QPainter::Antialiasing ); p.setPen( Qt::NoPen ); - + if( useOxygenShadows() ) { - + //--------------------------------------------------------------- // Active shadow texture - + QRadialGradient rg( size, size, size ); QColor c = color; c.setAlpha( 255 ); rg.setColorAt( 4.4/size, c ); @@ -917,10 +917,10 @@ namespace Nitrogen c.setAlpha( 180 ); rg.setColorAt( 5/size, c ); c.setAlpha( 25 ); rg.setColorAt( 5.5/size, c ); c.setAlpha( 0 ); rg.setColorAt( 6.5/size, c ); - + p.setBrush( rg ); p.drawRect( shadow.rect() ); - + rg = QRadialGradient( size, size, size ); c = color; c.setAlpha( 255 ); rg.setColorAt( 4.4/size, c ); @@ -937,10 +937,10 @@ namespace Nitrogen p.drawRect( shadow.rect() ); } else { - + //--------------------------------------------------------------- // Inactive shadow texture - + QRadialGradient rg = QRadialGradient( size, size+4, size ); QColor c = QColor( Qt::black ); c.setAlpha( 0.12*255 ); rg.setColorAt( 4.5/size, c ); @@ -955,7 +955,7 @@ namespace Nitrogen p.setPen( Qt::NoPen ); p.setBrush( rg ); p.drawRect( shadow.rect() ); - + rg = QRadialGradient( size, size+2, size ); c = QColor( Qt::black ); c.setAlpha( 0.25*255 ); rg.setColorAt( 4.5/size, c ); @@ -968,7 +968,7 @@ namespace Nitrogen p.setPen( Qt::NoPen ); p.setBrush( rg ); p.drawRect( shadow.rect() ); - + rg = QRadialGradient( size, size+0.2, size ); c = color; c = QColor( Qt::black ); @@ -981,7 +981,7 @@ namespace Nitrogen p.setPen( Qt::NoPen ); p.setBrush( rg ); p.drawRect( shadow.rect() ); - + rg = QRadialGradient( size, size, size ); c = color; c.setAlpha( 255 ); rg.setColorAt( 4.0/size, c ); @@ -990,34 +990,34 @@ namespace Nitrogen p.setPen( Qt::NoPen ); p.setBrush( rg ); p.drawRect( shadow.rect() ); - + } - + // draw the corner of the window - actually all 4 corners as one circle QLinearGradient lg = QLinearGradient(0.0, size-4.5, 0.0, size+4.5); if( configuration().frameBorder() < NitrogenConfiguration::BorderTiny ) { - - // for no + + // for no lg.setColorAt(0.52, helper().backgroundTopColor(color)); lg.setColorAt(1.0, helper().backgroundBottomColor(color) ); - + } else { - + QColor light = helper().calcLightColor( helper().backgroundTopColor(color) ); QColor dark = helper().calcDarkColor(helper().backgroundBottomColor(color)); - + lg.setColorAt(0.52, light); lg.setColorAt(1.0, dark); - + } p.setBrush( Qt::NoBrush ); p.setPen(QPen(lg, 0.8)); p.drawEllipse(QRectF(size-4, size-4, 8, 8)); - + p.end(); return shadow; } - + } diff --git a/clients/nitrogen/nitrogenclient.h b/clients/nitrogen/nitrogenclient.h index 2cbcd61603..7e14adf88d 100644 --- a/clients/nitrogen/nitrogenclient.h +++ b/clients/nitrogen/nitrogenclient.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenclient.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (c) 2003, 2004 David Johnson // Copyright (c) 2006, 2007 Riccardo Iaconelli @@ -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 @@ -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 diff --git a/clients/nitrogen/nitrogenconfiguration.cpp b/clients/nitrogen/nitrogenconfiguration.cpp index 18f82860f7..db3e9591aa 100644 --- a/clients/nitrogen/nitrogenconfiguration.cpp +++ b/clients/nitrogen/nitrogenconfiguration.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenconfiguration.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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() && diff --git a/clients/nitrogen/nitrogenconfiguration.h b/clients/nitrogen/nitrogenconfiguration.h index 1a6bb08f1f..7a70c3a9d7 100644 --- a/clients/nitrogen/nitrogenconfiguration.h +++ b/clients/nitrogen/nitrogenconfiguration.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenconfiguration.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 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 diff --git a/clients/nitrogen/nitrogenexception.cpp b/clients/nitrogen/nitrogenexception.cpp index 5d44b03900..065338b410 100644 --- a/clients/nitrogen/nitrogenexception.cpp +++ b/clients/nitrogen/nitrogenexception.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexception.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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; } - + } diff --git a/clients/nitrogen/nitrogenexception.h b/clients/nitrogen/nitrogenexception.h index 9e5d6a2f0c..df4735b945 100644 --- a/clients/nitrogen/nitrogenexception.h +++ b/clients/nitrogen/nitrogenexception.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexception.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 diff --git a/clients/nitrogen/nitrogenexceptionlist.cpp b/clients/nitrogen/nitrogenexceptionlist.cpp index 087194aea9..b4e6e95a78 100644 --- a/clients/nitrogen/nitrogenexceptionlist.cpp +++ b/clients/nitrogen/nitrogenexceptionlist.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptionlist.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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; } - + } diff --git a/clients/nitrogen/nitrogenexceptionlist.h b/clients/nitrogen/nitrogenexceptionlist.h index 760ce945bb..c699863b93 100644 --- a/clients/nitrogen/nitrogenexceptionlist.h +++ b/clients/nitrogen/nitrogenexceptionlist.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogenexceptionlist.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -33,35 +33,35 @@ namespace Nitrogen { - + //! nitrogen exceptions list class NitrogenExceptionList: public QList { - + 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 diff --git a/clients/nitrogen/nitrogensizegrip.cpp b/clients/nitrogen/nitrogensizegrip.cpp index 7ee6640a9d..6fc19bacf0 100644 --- a/clients/nitrogen/nitrogensizegrip.cpp +++ b/clients/nitrogen/nitrogensizegrip.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogensizegrip.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 ); } - + } diff --git a/clients/nitrogen/nitrogensizegrip.h b/clients/nitrogen/nitrogensizegrip.h index 5f7d17d024..d7e4c1a385 100644 --- a/clients/nitrogen/nitrogensizegrip.h +++ b/clients/nitrogen/nitrogensizegrip.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // nitrogensizegrip.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -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 diff --git a/clients/nitrogen/x11util.cpp b/clients/nitrogen/x11util.cpp index a5e91e3f78..92d4094c71 100644 --- a/clients/nitrogen/x11util.cpp +++ b/clients/nitrogen/x11util.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // x11util.cpp // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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; - + } } diff --git a/clients/nitrogen/x11util.h b/clients/nitrogen/x11util.h index 821abc62e2..b7396233dd 100644 --- a/clients/nitrogen/x11util.h +++ b/clients/nitrogen/x11util.h @@ -4,7 +4,7 @@ ////////////////////////////////////////////////////////////////////////////// // x11util.h // ------------------- -// +// // Copyright (c) 2009 Hugo Pereira Da Costa // // 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 @@ -36,16 +36,16 @@ #include #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 AtomNameMap; - + typedef std::map AtomNameMap; + //! atom names void _initializeAtomNames( void ); - + //! atom names const AtomNameMap& _atomNames( void ) const { return atom_names_; } - + AtomNameMap atom_names_; - + //! supported atoms typedef std::map SupportedAtomMap; - + //! supported atoms const SupportedAtomMap& _supportedAtoms( void ) const { return supported_atoms_; } - + SupportedAtomMap supported_atoms_; - + #ifdef Q_WS_X11 - + //! atom map typedef std::map AtomMap; - + //! atoms // const AtomMap& _atoms( void ) const AtomMap& _atoms( void ) { return atoms_; } - + //! atoms AtomMap atoms_; - + #endif - + }; - + } #endif