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-09-20 07:42:03 +00:00
|
|
|
#include <QtGui/QGroupBox>
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
#include <QtGui/QLayout>
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <KLocale>
|
2009-09-13 16:43:26 +00:00
|
|
|
#include <KPushButton>
|
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
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenExceptionDialog::OxygenExceptionDialog( QWidget* parent ):
|
2009-09-13 16:43:26 +00:00
|
|
|
KDialog( parent ),
|
|
|
|
detectDialog(0)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// define buttons
|
|
|
|
setButtons( Ok|Cancel );
|
2009-09-13 16:43:26 +00:00
|
|
|
showButtonSeparator( false );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// main widget
|
|
|
|
QWidget* widget = new QWidget( this );
|
|
|
|
setMainWidget( widget );
|
|
|
|
|
|
|
|
widget->setLayout( new QVBoxLayout() );
|
|
|
|
widget->layout()->setMargin(0);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// exception definition
|
|
|
|
QGroupBox* box;
|
2009-09-15 00:58:51 +00:00
|
|
|
widget->layout()->addWidget( box = new QGroupBox( i18n( "Window Identification" ), widget ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QGridLayout* gridLayout = new QGridLayout();
|
|
|
|
box->setLayout( gridLayout );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QLabel *label;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// exception type
|
2009-09-15 00:58:51 +00:00
|
|
|
gridLayout->addWidget( label = new QLabel( i18n( "Matching window property:" ), box ), 0, 0, 1, 1 );
|
2009-09-16 06:09:31 +00:00
|
|
|
gridLayout->addWidget( exceptionType = new KComboBox(box), 0, 1, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
exceptionType->insertItems(0, QStringList()
|
2009-09-15 07:12:54 +00:00
|
|
|
<< OxygenException::typeName( OxygenException::WindowClassName, true )
|
|
|
|
<< OxygenException::typeName( OxygenException::WindowTitle, true )
|
2009-09-13 16:43:26 +00:00
|
|
|
);
|
2009-09-04 19:10:47 +00:00
|
|
|
exceptionType->setToolTip( i18n(
|
2009-09-15 00:58:51 +00:00
|
|
|
"Select here the window property used to identify windows \n"
|
|
|
|
"to which the specific decoration options apply." ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 00:58:51 +00:00
|
|
|
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-13 16:43:26 +00:00
|
|
|
KPushButton* button = new KPushButton( i18n( "&Detect Window Properties" ), box );
|
|
|
|
gridLayout->addWidget( button, 2, 0, 1, 2, Qt::AlignRight|Qt::AlignVCenter );
|
|
|
|
connect( button, SIGNAL( clicked( void ) ), SLOT( selectWindowProperties() ) );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// regular expression
|
2009-08-24 07:31:29 +00:00
|
|
|
gridLayout->addWidget( label = new QLabel( i18n( "Regular expression to match: " ), box ), 1, 0, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
gridLayout->addWidget( exceptionEditor = new KLineEdit( box ), 1, 1, 1, 1 );
|
|
|
|
exceptionEditor->setClearButtonShown( true );
|
|
|
|
exceptionEditor->setToolTip( i18n(
|
2009-09-15 00:58:51 +00:00
|
|
|
"Type here the regular expression used to identify windows \n"
|
|
|
|
"to which the specific decoration options apply." ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-15 00:58:51 +00:00
|
|
|
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// decoration flags
|
2009-09-15 00:58:51 +00:00
|
|
|
widget->layout()->addWidget( box = new QGroupBox( i18n( "Decoration Options" ), widget ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
gridLayout = new QGridLayout();
|
|
|
|
box->setLayout( gridLayout );
|
|
|
|
|
|
|
|
QCheckBox* checkbox;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// border size
|
2009-09-03 22:41:06 +00:00
|
|
|
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Border size:" ), box ), 0, 0, 1, 1 );
|
2009-09-16 06:09:31 +00:00
|
|
|
gridLayout->addWidget( frameBorder = new KComboBox(box), 0, 1, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
frameBorder->insertItems(0, QStringList()
|
2009-09-15 07:12:54 +00:00
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderNone, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderNoSide, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderTiny, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderDefault, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderLarge, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderVeryLarge, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderHuge, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderVeryHuge, true )
|
|
|
|
<< OxygenConfiguration::frameBorderName( OxygenConfiguration::BorderOversized, true )
|
2009-08-25 04:51:08 +00:00
|
|
|
);
|
2009-09-04 19:10:47 +00:00
|
|
|
frameBorder->setEnabled( false );
|
2009-09-15 07:12:54 +00:00
|
|
|
checkboxes_.insert( std::make_pair( OxygenException::FrameBorder, checkbox ) );
|
2009-08-24 07:29:46 +00:00
|
|
|
checkbox->setToolTip( i18n("If checked, specified frame border is used in place of default value.") );
|
2009-09-04 19:10:47 +00:00
|
|
|
connect( checkbox, SIGNAL( toggled( bool ) ), frameBorder, SLOT( setEnabled( bool ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// blend color
|
2009-09-03 22:41:06 +00:00
|
|
|
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Background style:" ), box ), 1, 0, 1, 1 );
|
2009-09-16 06:09:31 +00:00
|
|
|
gridLayout->addWidget( blendColor = new KComboBox(box), 1, 1, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
blendColor->insertItems(0, QStringList()
|
2009-09-15 07:12:54 +00:00
|
|
|
<< OxygenException::blendColorName( OxygenException::NoBlending, true )
|
|
|
|
<< OxygenException::blendColorName( OxygenException::RadialBlending, true ) );
|
2009-09-04 19:10:47 +00:00
|
|
|
blendColor->setEnabled( false );
|
2009-09-15 07:12:54 +00:00
|
|
|
checkboxes_.insert( std::make_pair( OxygenException::BlendColor, checkbox ) );
|
2009-08-24 07:29:46 +00:00
|
|
|
checkbox->setToolTip( i18n("If checked, specified blending color is used in title bar in place of default value.") );
|
2009-09-04 19:10:47 +00:00
|
|
|
connect( checkbox, SIGNAL( toggled( bool ) ), blendColor, SLOT( setEnabled( bool ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-02 02:19:26 +00:00
|
|
|
// size grip
|
2009-09-15 00:58:51 +00:00
|
|
|
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Extra size grip display:" ), box ), 2, 0, 1, 1 );
|
2009-09-16 06:09:31 +00:00
|
|
|
gridLayout->addWidget( sizeGripMode = new KComboBox( box ), 2, 1, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
sizeGripMode->insertItems(0, QStringList()
|
2009-09-15 07:12:54 +00:00
|
|
|
<< OxygenConfiguration::sizeGripModeName( OxygenConfiguration::SizeGripNever, true )
|
|
|
|
<< OxygenConfiguration::sizeGripModeName( OxygenConfiguration::SizeGripWhenNeeded, true )
|
2009-09-02 02:19:26 +00:00
|
|
|
);
|
2009-09-04 19:10:47 +00:00
|
|
|
sizeGripMode->setEnabled( false );
|
2009-09-15 07:12:54 +00:00
|
|
|
checkboxes_.insert( std::make_pair( OxygenException::SizeGripMode, checkbox ) );
|
2009-09-04 19:10:47 +00:00
|
|
|
connect( checkbox, SIGNAL( toggled( bool ) ), sizeGripMode, SLOT( setEnabled( bool ) ) );
|
|
|
|
|
|
|
|
// outline active window title
|
|
|
|
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Outline active window title:" ), box ), 3, 0, 1, 1 );
|
|
|
|
gridLayout->addWidget( titleOutline = new ComboBox( box ), 3, 1, 1, 1 );
|
|
|
|
titleOutline->setEnabled( false );
|
2009-09-15 07:12:54 +00:00
|
|
|
checkboxes_.insert( std::make_pair( OxygenException::TitleOutline, checkbox ) );
|
2009-09-04 19:10:47 +00:00
|
|
|
connect( checkbox, SIGNAL( toggled( bool ) ), titleOutline, SLOT( setEnabled( bool ) ) );
|
2009-09-02 02:19:26 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// separator
|
2009-09-15 00:58:51 +00:00
|
|
|
gridLayout->addWidget( checkbox = new QCheckBox( i18n("Draw separator between title bar and active window contents:" ), box ), 4, 0, 1, 1 );
|
2009-09-04 19:10:47 +00:00
|
|
|
gridLayout->addWidget( drawSeparator = new ComboBox( box ), 4, 1, 1, 1 );
|
|
|
|
drawSeparator->setEnabled( false );
|
2009-09-15 07:12:54 +00:00
|
|
|
checkboxes_.insert( std::make_pair( OxygenException::DrawSeparator, checkbox ) );
|
2009-09-04 19:10:47 +00:00
|
|
|
connect( checkbox, SIGNAL( toggled( bool ) ), drawSeparator, SLOT( setEnabled( bool ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenExceptionDialog::setException( OxygenException exception )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// store exception internally
|
|
|
|
exception_ = exception;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// type
|
2009-09-09 06:20:06 +00:00
|
|
|
exceptionType->setCurrentIndex( exceptionType->findText( exception.typeName( true ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// regular expression
|
2009-09-04 19:10:47 +00:00
|
|
|
exceptionEditor->setText( exception.regExp().pattern() );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// border size
|
2009-09-04 19:10:47 +00:00
|
|
|
frameBorder->setCurrentIndex( frameBorder->findText( exception.frameBorderName( true ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// blend color
|
2009-09-04 19:10:47 +00:00
|
|
|
blendColor->setCurrentIndex( blendColor->findText( exception.blendColorName( true ) ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-02 02:19:26 +00:00
|
|
|
// size grip
|
2009-09-04 19:10:47 +00:00
|
|
|
sizeGripMode->setCurrentIndex( sizeGripMode->findText( exception.sizeGripModeName( true ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// flags
|
2009-09-04 19:10:47 +00:00
|
|
|
drawSeparator->setValue( exception.drawSeparator() );
|
|
|
|
titleOutline->setValue( exception.drawTitleOutline() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// mask
|
2009-09-16 06:09:31 +00:00
|
|
|
for( CheckBoxMap::iterator iter = checkboxes_.begin(); iter != checkboxes_.end(); ++iter )
|
2009-08-22 08:24:06 +00:00
|
|
|
{ iter->second->setChecked( exception.mask() & iter->first ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenException OxygenExceptionDialog::exception( void ) const
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenException exception( exception_ );
|
|
|
|
exception.setType( OxygenException::type( exceptionType->currentText(), true ) );
|
2009-09-04 19:10:47 +00:00
|
|
|
exception.regExp().setPattern( exceptionEditor->text() );
|
2009-09-15 07:12:54 +00:00
|
|
|
exception.setFrameBorder( OxygenException::frameBorder( frameBorder->currentText(), true ) );
|
|
|
|
exception.setBlendColor( OxygenException::blendColor( blendColor->currentText(), true ) );
|
|
|
|
exception.setSizeGripMode( OxygenException::sizeGripMode( sizeGripMode->currentText(), true ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-30 17:26:47 +00:00
|
|
|
// flags
|
2009-09-04 19:10:47 +00:00
|
|
|
exception.setDrawSeparator( drawSeparator->isChecked() );
|
|
|
|
exception.setDrawTitleOutline( titleOutline->isChecked() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// mask
|
2009-09-15 07:12:54 +00:00
|
|
|
unsigned int mask = OxygenException::None;
|
2009-09-16 06:09:31 +00:00
|
|
|
for( CheckBoxMap::const_iterator iter = checkboxes_.begin(); iter != checkboxes_.end(); ++iter )
|
2009-08-22 08:24:06 +00:00
|
|
|
{ if( iter->second->isChecked() ) mask |= iter->first; }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
exception.setMask( mask );
|
|
|
|
return exception;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 16:43:26 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenExceptionDialog::selectWindowProperties( void )
|
2009-09-13 16:43:26 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// create widget
|
|
|
|
if( !detectDialog )
|
|
|
|
{
|
|
|
|
detectDialog = new DetectDialog( this );
|
|
|
|
connect( detectDialog, SIGNAL( detectionDone( bool ) ), SLOT( readWindowProperties( bool ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
detectDialog->detect(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenExceptionDialog::readWindowProperties( bool valid )
|
2009-09-13 16:43:26 +00:00
|
|
|
{
|
|
|
|
assert( detectDialog );
|
|
|
|
if( valid )
|
|
|
|
{
|
|
|
|
|
|
|
|
// type
|
2009-09-15 07:12:54 +00:00
|
|
|
exceptionType->setCurrentIndex( exceptionType->findText( OxygenException::typeName( detectDialog->exceptionType(), true ) ) );
|
2009-09-13 16:43:26 +00:00
|
|
|
|
|
|
|
// window info
|
|
|
|
const KWindowInfo& info( detectDialog->windowInfo() );
|
|
|
|
|
|
|
|
switch( detectDialog->exceptionType() )
|
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
case OxygenException::WindowClassName:
|
2009-09-13 16:43:26 +00:00
|
|
|
exceptionEditor->setText( info.windowClassClass() );
|
|
|
|
break;
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
case OxygenException::WindowTitle:
|
2009-09-13 16:43:26 +00:00
|
|
|
exceptionEditor->setText( info.name() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: assert( false );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete detectDialog;
|
|
|
|
detectDialog = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
const QString OxygenExceptionDialog::ComboBox::Yes( i18n("Enabled") );
|
|
|
|
const QString OxygenExceptionDialog::ComboBox::No( i18n("Disabled") );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenExceptionDialog::ComboBox::ComboBox( QWidget* parent ):
|
2009-09-16 06:09:31 +00:00
|
|
|
KComboBox( parent )
|
2009-08-30 17:26:47 +00:00
|
|
|
{ insertItems( 0, QStringList() << Yes << No ); }
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenExceptionDialog::ComboBox::setValue( bool checked )
|
2009-08-30 17:26:47 +00:00
|
|
|
{ setCurrentIndex( findText( checked ? Yes:No ) ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenExceptionDialog::ComboBox::isChecked( void ) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{ return currentText() == Yes; }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 06:27:49 +00:00
|
|
|
}
|