// Implementation of the QTreePrefsDialog class.
#include "qtreeprefsdialog.h"
QTreePrefsDialog::QTreePrefsDialog( QWidget* parent )
: QTabDialog( parent, 0, TRUE )
{
//Read current settings.
settings.insertSearchPath( QSettings::Windows, "/Perforce" );
colset = settings.readNumEntry( "/P4QTree/qtrcol", TREE_OLDSKOOL );
jobset = settings.readBoolEntry( "/P4QTree/jobs", true );
startset = settings.readNumEntry( "/P4QTree/cropstart", false );
endset = settings.readNumEntry( "/P4QTree/cropend", false );
QString ss = settings.readEntry( "/P4QTree/sdate" );
QString es = settings.readEntry( "/P4QTree/edate" );
startdate = QDate::fromString( ss, ISODate );
enddate = QDate::fromString( es, ISODate );
showall = settings.readEntry( "/P4QTree/showall" );
//Build dialog.
setCaption( "P4QTree Preferences" );
//Color scheme selection.
colorradio = new QButtonGroup( 1, Horizontal, "", this );
colorradio->setFrameStyle( QFrame::NoFrame );
colorradio->setInsideMargin( 5 );
colornewbutton = new QRadioButton( "Post-Modern", colorradio );
coloroldbutton = new QRadioButton( "Old-School", colorradio );
colorradio->setButton( colset );
addTab( colorradio, "Colors" );
//Queries. (was: Performance)
perfbox = new QGroupBox( 1, Horizontal, "", this );
perfbox->setFrameStyle( QFrame::NoFrame );
perfbox->setInsideMargin( 5 );
jobscheck = new QCheckBox( "Disable jobs", perfbox );
jobscheck->setChecked( !jobset );
allcheck = new QCheckBox( "Show all integs", perfbox );
allcheck->setChecked( showall );
addTab( perfbox, "Queries" );
//Date cropping
cropbox = new QGroupBox( 1, Horizontal, "", this );
cropbox->setFrameStyle( QFrame::NoFrame );
cropbox->setInsideMargin( 5 );
startcheck = new QCheckBox( "Only display changes after", cropbox );
startedit = new QDateEdit( cropbox );
endcheck = new QCheckBox( "Only display changes before", cropbox );
endedit = new QDateEdit( cropbox );
connect( startcheck, SIGNAL( toggled( bool ) ),
startedit, SLOT( setEnabled( bool ) ) );
connect( endcheck, SIGNAL( toggled( bool ) ),
endedit, SLOT( setEnabled( bool ) ) );
startcheck->setChecked( startset );
endcheck->setChecked( endset );
startedit->setDate( startdate );
endedit->setDate( enddate );
startedit->setEnabled( startcheck->isChecked() );
endedit->setEnabled( endcheck->isChecked() );
addTab( cropbox, "Cropping" );
setOkButton();
setCancelButton();
connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( Save() ) );
// Done!
setFixedSize( sizeHint() ); //this doesn't work - Qt bug.
show();
}
QTreePrefsDialog::~QTreePrefsDialog()
{
}
void QTreePrefsDialog::Save()
{
status = 0;
//Color scheme selection.
int colnew;
if ( colorradio->selected() == coloroldbutton ) colnew = TREE_OLDSKOOL;
else colnew = TREE_POSTMODN;
if ( colnew != colset ) //change settings
{
settings.writeEntry( "/P4QTree/qtrcol", colnew );
status = 1;
}
//Query settings.
bool jobnew, allnew;
jobnew = !jobscheck->isChecked();
allnew = allcheck->isChecked();
if ( jobnew != jobset )
{
settings.writeEntry( "/P4QTree/jobs", jobnew );
status = 2;
}
if ( allnew != showall )
{
settings.writeEntry( "/P4QTree/showall", allnew );
status = 2;
}
//Date cropping.
char sbnew, ebnew;
if ( startcheck->isChecked() ) sbnew = 'd';
else sbnew = '\0';
if ( endcheck->isChecked() ) ebnew = 'd';
else ebnew = '\0';
QDate sdnew = startedit->date();
QDate ednew = endedit->date();
if ( ( sbnew != startset ) || ( ebnew != endset ) ||
( sdnew != startdate ) || ( ednew != enddate ) )
{
settings.writeEntry( "/P4QTree/cropstart", sbnew );
settings.writeEntry( "/P4QTree/cropend", ebnew );
settings.writeEntry( "/P4QTree/sdate", sdnew.toString( ISODate ) );
settings.writeEntry( "/P4QTree/edate", ednew.toString( ISODate ) );
status = 2;
}
}