NLogRecent: Move Reset button to NLogDialog button box
[nomnom.git] / src / log / nlogdialog.cpp
blob3a4016dd6559b3299f55b72c31a024d176e30208
1 /* NomNom
2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "config.h"
20 #include <QCoreApplication>
21 #include <QDialogButtonBox>
22 #include <QPushButton>
23 #include <QMessageBox>
24 #include <QVBoxLayout>
25 #include <QToolBox>
27 #include <NLogDialog>
28 #include <NSettings>
29 #include <NUtil>
31 namespace nn
34 NLogDialog::NLogDialog(QWidget *parent/*=NULL*/)
35 : QDialog(parent), _toolbox(NULL)
38 // Toolbox
40 _toolbox = new QToolBox;
42 NLogRecent *recent = new NLogRecent;
43 connect(recent, SIGNAL(selected(QString)), this, SLOT(selected(QString)));
45 _toolbox->addItem(recent, tr("&Recent"));
47 // Button box
49 QDialogButtonBox *bb =
50 new QDialogButtonBox(QDialogButtonBox::Ok
51 | QDialogButtonBox::Cancel
52 | QDialogButtonBox::Reset);
54 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
55 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
57 connect(bb->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
58 this, SLOT(reset()));
60 // Layout
62 QVBoxLayout *box = new QVBoxLayout;
63 box->addWidget(_toolbox);
64 box->addWidget(bb);
65 setLayout(box);
67 // Window
69 setMinimumSize(QSize(500,400));
70 setWindowTitle(tr("Log"));
71 setSizeGripEnabled(true);
73 foreachWidget();
76 void NLogDialog::foreachWidget()
78 const int c = _toolbox->count();
79 for (int i=0; i<c; ++i)
81 NLogWidget *l = dynamic_cast<NLogWidget*>(_toolbox->widget(i));
82 l->init();
86 void NLogDialog::done(int n)
88 if (n == QDialog::Accepted)
90 if (_selected.isEmpty())
92 _toolbox->setCurrentIndex(0);
93 info(this, tr("Please select an item from the list"));
94 return;
97 QDialog::done(n);
98 close();
101 void NLogDialog::selected(QString s)
103 _selected = s;
106 QString NLogDialog::selected() const
108 return _selected;
111 void NLogDialog::reset()
113 NLogWidget *l = dynamic_cast<NLogWidget*>(_toolbox->currentWidget());
114 l->reset();
117 // NLogWidget
119 NLogWidget::NLogWidget(QWidget *parent/*=NULL*/)
120 : QWidget(parent)
124 } // namespace nn
126 /* vim: set ts=2 sw=2 tw=72 expandtab: */