2009-08-24 16:15:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygenexceptiondialog.cpp
|
2009-08-24 16:15:14 +00:00
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-24 16:15:14 +00:00
|
|
|
//
|
|
|
|
// 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
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-24 16:15:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-16 06:09:31 +00:00
|
|
|
#include "oxygenexceptiondialog.h"
|
|
|
|
#include "oxygenexceptiondialog.moc"
|
|
|
|
#include "oxygendetectwidget.h"
|
|
|
|
|
2009-09-13 16:43:26 +00:00
|
|
|
#include <cassert>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________
|
|
|
|
ExceptionDialog::ExceptionDialog( QWidget* parent ):
|
|
|
|
KDialog( parent ),
|
2011-02-24 16:47:38 +00:00
|
|
|
_detectDialog(0)
|
2009-09-13 16:43:26 +00:00
|
|
|
{
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// define buttons
|
|
|
|
setButtons( Ok|Cancel );
|
|
|
|
QWidget* local( new QWidget( this ) );
|
|
|
|
ui.setupUi( local );
|
|
|
|
setMainWidget( local );
|
|
|
|
|
|
|
|
// exception type
|
|
|
|
ui.exceptionType->insertItems( 0, QStringList()
|
|
|
|
<< Exception::typeName( Exception::WindowClassName, true )
|
|
|
|
<< Exception::typeName( Exception::WindowTitle, true )
|
|
|
|
);
|
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.detectDialogButton, SIGNAL(clicked()), SLOT(selectWindowProperties()) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// border size
|
|
|
|
ui.frameBorderComboBox->insertItems(0, QStringList()
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderNone, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderNoSide, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderTiny, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderDefault, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderLarge, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderVeryLarge, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderHuge, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderVeryHuge, true )
|
|
|
|
<< Configuration::frameBorderName( Configuration::BorderOversized, true )
|
|
|
|
);
|
|
|
|
ui.frameBorderComboBox->setEnabled( false );
|
2011-02-24 16:47:38 +00:00
|
|
|
_checkBoxes.insert( std::make_pair( Exception::FrameBorder, ui.frameBorderCheckBox ) );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.frameBorderCheckBox, SIGNAL(toggled(bool)), ui.frameBorderComboBox, SLOT(setEnabled(bool)) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// blend color
|
|
|
|
ui.blendColorComboBox->insertItems(0, QStringList()
|
|
|
|
<< Exception::blendColorName( Exception::NoBlending, true )
|
2010-12-22 19:23:46 +00:00
|
|
|
<< Exception::blendColorName( Exception::RadialBlending, true )
|
|
|
|
<< Exception::blendColorName( Exception::BlendFromStyle, true )
|
|
|
|
);
|
2010-05-02 18:34:08 +00:00
|
|
|
ui.blendColorComboBox->setEnabled( false );
|
2011-02-24 16:47:38 +00:00
|
|
|
_checkBoxes.insert( std::make_pair( Exception::BlendColor, ui.blendColorCheckBox ) );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.blendColorCheckBox, SIGNAL(toggled(bool)), ui.blendColorComboBox, SLOT(setEnabled(bool)) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// size grip
|
|
|
|
ui.sizeGripComboBox->insertItems(0, QStringList()
|
|
|
|
<< Configuration::sizeGripModeName( Configuration::SizeGripNever, true )
|
|
|
|
<< Configuration::sizeGripModeName( Configuration::SizeGripWhenNeeded, true )
|
|
|
|
);
|
|
|
|
ui.sizeGripComboBox->setEnabled( false );
|
2011-02-24 16:47:38 +00:00
|
|
|
_checkBoxes.insert( std::make_pair( Exception::SizeGripMode, ui.sizeGripCheckBox ) );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.sizeGripCheckBox, SIGNAL(toggled(bool)), ui.sizeGripComboBox, SLOT(setEnabled(bool)) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// outline active window title
|
|
|
|
ui.titleOutlineComboBox->insertItems(0, QStringList() << i18nc( "outline window title", "Enabled" ) << i18nc( "outline window title", "Disabled" ) );
|
|
|
|
ui.titleOutlineComboBox->setEnabled( false );
|
2011-02-24 16:47:38 +00:00
|
|
|
_checkBoxes.insert( std::make_pair( Exception::TitleOutline, ui.titleOutlineCheckBox ) );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.titleOutlineCheckBox, SIGNAL(toggled(bool)), ui.titleOutlineComboBox, SLOT(setEnabled(bool)) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// separator
|
|
|
|
ui.separatorComboBox->setEnabled( false );
|
2011-02-24 16:47:38 +00:00
|
|
|
_checkBoxes.insert( std::make_pair( Exception::DrawSeparator, ui.separatorCheckBox ) );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui.separatorCheckBox, SIGNAL(toggled(bool)), ui.separatorComboBox, SLOT(setEnabled(bool)) );
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________
|
|
|
|
void ExceptionDialog::setException( Exception exception )
|
2009-09-13 16:43:26 +00:00
|
|
|
{
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// store exception internally
|
2011-02-24 16:47:38 +00:00
|
|
|
_exception = exception;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// type
|
|
|
|
ui.exceptionType->setCurrentIndex( ui.exceptionType->findText( exception.typeName( true ) ) );
|
|
|
|
ui.exceptionEditor->setText( exception.regExp().pattern() );
|
|
|
|
ui.frameBorderComboBox->setCurrentIndex( ui.frameBorderComboBox->findText( exception.frameBorderName( true ) ) );
|
|
|
|
ui.blendColorComboBox->setCurrentIndex( ui.blendColorComboBox->findText( exception.blendColorName( true ) ) );
|
|
|
|
ui.sizeGripComboBox->setCurrentIndex( ui.sizeGripComboBox->findText( exception.sizeGripModeName( true ) ) );
|
2010-10-03 02:22:56 +00:00
|
|
|
ui.separatorComboBox->setCurrentIndex( exception.separatorMode() );
|
2010-05-02 18:34:08 +00:00
|
|
|
ui.titleOutlineComboBox->setCurrentIndex( ui.titleOutlineComboBox->findText( exception.drawTitleOutline() ? i18nc( "outline window title", "Enabled" ) : i18nc( "outline window title", "Disabled" ) ) );
|
|
|
|
ui.hideTitleBar->setChecked( exception.hideTitleBar() );
|
|
|
|
|
|
|
|
// mask
|
2011-02-24 16:47:38 +00:00
|
|
|
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
|
2010-05-02 18:34:08 +00:00
|
|
|
{ iter->second->setChecked( exception.mask() & iter->first ); }
|
|
|
|
|
|
|
|
}
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________
|
|
|
|
Exception ExceptionDialog::exception( void ) const
|
|
|
|
{
|
2011-02-24 16:47:38 +00:00
|
|
|
Exception exception( _exception );
|
2010-05-02 18:34:08 +00:00
|
|
|
exception.setType( Exception::type( ui.exceptionType->currentText(), true ) );
|
|
|
|
exception.regExp().setPattern( ui.exceptionEditor->text() );
|
|
|
|
exception.setFrameBorder( Exception::frameBorder( ui.frameBorderComboBox->currentText(), true ) );
|
|
|
|
exception.setBlendColor( Exception::blendColor( ui.blendColorComboBox->currentText(), true ) );
|
|
|
|
exception.setSizeGripMode( Exception::sizeGripMode( ui.sizeGripComboBox->currentText(), true ) );
|
|
|
|
|
|
|
|
// flags
|
2010-10-03 02:22:56 +00:00
|
|
|
switch( ui.separatorComboBox->currentIndex() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: exception.setSeparatorMode( Configuration::SeparatorNever ); break;
|
|
|
|
case 1: exception.setSeparatorMode( Configuration::SeparatorActive ); break;
|
|
|
|
case 2: exception.setSeparatorMode( Configuration::SeparatorAlways ); break;
|
|
|
|
}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
exception.setDrawTitleOutline( ui.titleOutlineComboBox->currentText() == i18nc( "outline window title", "Enabled" ) );
|
|
|
|
exception.setHideTitleBar( ui.hideTitleBar->isChecked() );
|
|
|
|
|
|
|
|
// mask
|
|
|
|
unsigned int mask = Exception::None;
|
2011-02-24 16:47:38 +00:00
|
|
|
for( CheckBoxMap::const_iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
|
2010-05-02 18:34:08 +00:00
|
|
|
{ if( iter->second->isChecked() ) mask |= iter->first; }
|
|
|
|
|
|
|
|
exception.setMask( mask );
|
|
|
|
return exception;
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________
|
|
|
|
void ExceptionDialog::selectWindowProperties( void )
|
|
|
|
{
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// create widget
|
2011-02-24 16:47:38 +00:00
|
|
|
if( !_detectDialog )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
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)) );
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2011-02-24 16:47:38 +00:00
|
|
|
_detectDialog->detect(0);
|
2009-09-13 16:43:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________
|
|
|
|
void ExceptionDialog::readWindowProperties( bool valid )
|
|
|
|
{
|
2011-02-24 16:47:38 +00:00
|
|
|
assert( _detectDialog );
|
2010-05-02 18:34:08 +00:00
|
|
|
if( valid )
|
|
|
|
{
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// type
|
2011-02-24 16:47:38 +00:00
|
|
|
ui.exceptionType->setCurrentIndex( ui.exceptionType->findText( Exception::typeName( _detectDialog->exceptionType(), true ) ) );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// window info
|
2011-02-24 16:47:38 +00:00
|
|
|
const KWindowInfo& info( _detectDialog->windowInfo() );
|
2010-05-02 18:34:08 +00:00
|
|
|
|
2011-02-24 16:47:38 +00:00
|
|
|
switch( _detectDialog->exceptionType() )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
|
|
|
case Exception::WindowClassName:
|
|
|
|
ui.exceptionEditor->setText( info.windowClassClass() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Exception::WindowTitle:
|
|
|
|
ui.exceptionEditor->setText( info.name() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: assert( false );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-24 16:47:38 +00:00
|
|
|
delete _detectDialog;
|
|
|
|
_detectDialog = 0;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
}
|
2009-09-13 16:43:26 +00:00
|
|
|
|
2009-08-24 06:27:49 +00:00
|
|
|
}
|