kwin/clients/oxygen/config/oxygenexceptiondialog.cpp

195 lines
7.7 KiB
C++
Raw Normal View History

//////////////////////////////////////////////////////////////////////////////
// oxygenexceptiondialog.cpp
// -------------------
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// 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.
//////////////////////////////////////////////////////////////////////////////
#include "oxygenexceptiondialog.h"
#include "oxygenexceptiondialog.moc"
#include "oxygendetectwidget.h"
namespace Oxygen
{
//___________________________________________
ExceptionDialog::ExceptionDialog( QWidget* parent ):
2013-08-01 15:20:16 +00:00
QDialog( parent ),
_detectDialog(0),
_changed( false )
{
2013-08-01 15:20:16 +00:00
setupUi( this );
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), this, SLOT(close()) );
// store checkboxes from ui into list
2013-08-01 15:20:16 +00:00
_checkBoxes.insert( FrameBorder, frameBorderCheckBox );
_checkBoxes.insert( BlendColor, blendColorCheckBox );
_checkBoxes.insert( SizeGripMode, sizeGripCheckBox );
_checkBoxes.insert( TitleOutline, titleOutlineCheckBox );
_checkBoxes.insert( DrawSeparator, separatorCheckBox );
// detect window properties
2013-08-01 15:20:16 +00:00
connect( detectDialogButton, SIGNAL(clicked()), SLOT(selectWindowProperties()) );
// connections
2013-08-01 15:20:16 +00:00
connect( exceptionType, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( exceptionEditor, SIGNAL(textChanged(QString)), SLOT(updateChanged()) );
connect( frameBorderComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( blendColorComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( sizeGripComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( titleOutlineComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( separatorComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
{ connect( iter.value(), SIGNAL(clicked()), SLOT(updateChanged()) ); }
2013-08-01 15:20:16 +00:00
connect( hideTitleBar, SIGNAL(clicked()), SLOT(updateChanged()) );
}
//___________________________________________
void ExceptionDialog::setException( ConfigurationPtr exception )
{
// store exception internally
2011-02-24 16:47:38 +00:00
_exception = exception;
// type
2013-08-01 15:20:16 +00:00
exceptionType->setCurrentIndex(_exception->exceptionType() );
exceptionEditor->setText( _exception->exceptionPattern() );
frameBorderComboBox->setCurrentIndex( _exception->frameBorder() );
blendColorComboBox->setCurrentIndex( _exception->blendStyle() );
sizeGripComboBox->setCurrentIndex( _exception->drawSizeGrip() );
separatorComboBox->setCurrentIndex( _exception->separatorMode() );
titleOutlineComboBox->setCurrentIndex( _exception->drawTitleOutline() );
hideTitleBar->setChecked( _exception->hideTitleBar() );
// mask
2011-02-24 16:47:38 +00:00
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
{ iter.value()->setChecked( _exception->mask() & iter.key() ); }
setChanged( false );
}
//___________________________________________
void ExceptionDialog::save( void )
{
2013-08-01 15:20:16 +00:00
_exception->setExceptionType( exceptionType->currentIndex() );
_exception->setExceptionPattern( exceptionEditor->text() );
_exception->setFrameBorder( frameBorderComboBox->currentIndex() );
_exception->setBlendStyle( blendColorComboBox->currentIndex() );
_exception->setDrawSizeGrip( sizeGripComboBox->currentIndex() );
_exception->setSeparatorMode( separatorComboBox->currentIndex() );
_exception->setDrawTitleOutline( titleOutlineComboBox->currentIndex() );
_exception->setHideTitleBar( hideTitleBar->isChecked() );
// mask
unsigned int mask = None;
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
{ if( iter.value()->isChecked() ) mask |= iter.key(); }
_exception->setMask( mask );
setChanged( false );
}
//___________________________________________
void ExceptionDialog::updateChanged( void )
{
bool modified( false );
2013-08-01 15:20:16 +00:00
if( _exception->exceptionType() != exceptionType->currentIndex() ) modified = true;
else if( _exception->exceptionPattern() != exceptionEditor->text() ) modified = true;
else if( _exception->frameBorder() != frameBorderComboBox->currentIndex() ) modified = true;
else if( _exception->blendStyle() != blendColorComboBox->currentIndex() ) modified = true;
else if( _exception->drawSizeGrip() != sizeGripComboBox->currentIndex() ) modified = true;
else if( _exception->separatorMode() != separatorComboBox->currentIndex() ) modified = true;
else if( _exception->drawTitleOutline() != titleOutlineComboBox->currentIndex() ) modified = true;
else if( _exception->hideTitleBar() != hideTitleBar->isChecked() ) modified = true;
else
{
// check mask
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
{
if( iter.value()->isChecked() != (bool)( _exception->mask() & iter.key() ) )
{
modified = true;
break;
}
}
}
setChanged( modified );
}
//___________________________________________
void ExceptionDialog::selectWindowProperties( void )
{
// create widget
2011-02-24 16:47:38 +00:00
if( !_detectDialog )
{
2011-02-24 16:47:38 +00:00
_detectDialog = new DetectDialog( this );
2011-08-17 21:51:55 +00:00
connect( _detectDialog, SIGNAL(detectionDone(bool)), SLOT(readWindowProperties(bool)) );
}
2011-02-24 16:47:38 +00:00
_detectDialog->detect(0);
}
//___________________________________________
void ExceptionDialog::readWindowProperties( bool valid )
{
Q_CHECK_PTR( _detectDialog );
if( valid )
{
// type
2013-08-01 15:20:16 +00:00
exceptionType->setCurrentIndex( _detectDialog->exceptionType() );
// window info
2011-02-24 16:47:38 +00:00
const KWindowInfo& info( _detectDialog->windowInfo() );
2011-02-24 16:47:38 +00:00
switch( _detectDialog->exceptionType() )
{
default:
case Configuration::ExceptionWindowClassName:
2013-08-01 15:20:16 +00:00
exceptionEditor->setText( QString::fromUtf8( info.windowClassClass() ) );
break;
case Configuration::ExceptionWindowTitle:
2013-08-01 15:20:16 +00:00
exceptionEditor->setText( info.name() );
break;
}
}
2011-02-24 16:47:38 +00:00
delete _detectDialog;
_detectDialog = 0;
}
}