1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/* This file is part of KCachegrind.
Copyright (c) 2009-2015 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
KCachegrind is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/*
* QCachegrind configuration dialog
*/
#include "configdialog.h"
#include <QWidget>
#include <QLabel>
#include <QFrame>
#include <QListWidget>
#include <QStackedWidget>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTimer>
#include "generalsettings.h"
#include "sourcesettings.h"
#include "colorsettings.h"
//
// ConfigDialog
//
ConfigDialog::ConfigDialog(TraceData* data, QWidget* parent, QString s)
: QDialog(parent)
{
setWindowTitle(tr("Configure QCachegrind"));
_listWidget = new QListWidget(this);
_listWidget->setMaximumWidth(140);
_widgetStack = new QStackedWidget(this);
_titleLabel = new QLabel(this);
QFont labelFont;
labelFont.setBold(true);
_titleLabel->setFont(labelFont);
_errorLabel = new QLabel(this);
_errorLabel->setIndent(9);
QDialogButtonBox* bbox = new QDialogButtonBox(this);
bbox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
QVBoxLayout* vbox1 = new QVBoxLayout();
vbox1->addWidget(_titleLabel);
QFrame* f1 = new QFrame(this);
f1->setFrameShape(QFrame::HLine);
vbox1->addWidget(f1);
vbox1->addWidget(_errorLabel);
vbox1->addWidget(_widgetStack);
QHBoxLayout* hbox = new QHBoxLayout();
hbox->addWidget(_listWidget);
hbox->addLayout(vbox1);
QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->addLayout(hbox);
QFrame* f2 = new QFrame(this);
f2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
vbox->addWidget(f2);
vbox->addWidget(bbox);
connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
connect(_listWidget, SIGNAL(currentTextChanged(QString)),
this, SLOT(listItemChanged(QString)));
connect(&_clearTimer, SIGNAL(timeout()), this, SLOT(clearError()));
addPage(new GeneralSettings(this));
addPage(new SourceSettings(data, this));
addPage(new ColorSettings(data, this));
activate(s);
}
void ConfigDialog::addPage(ConfigPage* p)
{
_widgetStack->addWidget(p);
_listWidget->addItem(p->title());
_pages.insert(p->title(), p);
}
void ConfigDialog::listItemChanged(QString s)
{
ConfigPage* p = _pages.value(s);
if (!p) return;
_titleLabel->setText(p->longTitle());
_widgetStack->setCurrentWidget(p);
if (!_activeSetting.isEmpty()) {
p->activate(_activeSetting);
_activeSetting.clear();
}
}
void ConfigDialog::clearError()
{
_errorLabel->setText(QString());
}
void ConfigDialog::activate(QString s)
{
if (s.isEmpty())
_listWidget->setCurrentRow(0);
QString page = s;
_activeSetting.clear();
int p = s.indexOf("/");
if (p>0) {
page = s.left(p);
_activeSetting = s.mid(p+1);
}
for(int row=0; row<_listWidget->count(); row++) {
QListWidgetItem* i = _listWidget->item(row);
if (i->text() != page) continue;
if (_listWidget->currentRow() == row)
// even without page change, forward activation
listItemChanged(page);
else
_listWidget->setCurrentRow(row);
}
}
QString ConfigDialog::currentPage()
{
return _listWidget->currentItem()->text();
}
void ConfigDialog::accept()
{
ConfigPage* p;
QString errorMsg, errorItem;
foreach(p, _pages)
if (!p->check(errorMsg, errorItem)) {
if (!errorMsg.isEmpty()) {
errorMsg = QString("<font color=red>%1</color>").arg(errorMsg);
_errorLabel->setText(errorMsg);
_clearTimer.start(5000);
}
activate(QString("%1/%2").arg(p->title(), errorItem));
return;
}
foreach(p, _pages)
p->accept();
QDialog::accept();
}
#include "configdialog.moc"
|