Recent: resize to "Title" column contents
[nomnom.git] / src / log / nlogdialog_recent.cpp
blob6d9cea6cfb1bce5058bcac6d04d61c10ad65fe02
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 <QVBoxLayout>
24 #include <QTextStream>
25 #include <QTreeWidget>
26 #include <QMessageBox>
28 #include <NRecentMutator>
29 #include <NRecentEntry>
30 #include <NLogDialog>
31 #include <NSettings>
32 #include <NUtil>
34 extern nn::NRecentMutator recent;
36 namespace nn
39 NLogRecent::NLogRecent(QWidget *parent/*=NULL*/)
40 : NLogWidget(parent), _treew(NULL)
43 // Widgets
45 _treew = new QTreeWidget;
46 _treew->setHeaderLabels(QStringList() << tr("Title") << tr("Added"));
47 _treew->setColumnCount(2);
49 connect(_treew, SIGNAL(itemSelectionChanged()), this, SLOT(selected()));
51 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Reset);
53 connect(bb->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
54 this, SLOT(reset()));
56 // Layout
58 QVBoxLayout *box = new QVBoxLayout;
59 box->addWidget(_treew);
60 box->addWidget(bb);
61 setLayout(box);
64 #ifdef _1
65 void NLogRecent::read()
67 recent.read();
69 #endif
71 void NLogRecent::init()
73 recent.populate(_treew);
74 _treew->resizeColumnToContents(0);
75 _treew->sortByColumn(1);
76 _treew->setSortingEnabled(true);
79 void NLogRecent::selected()
81 QTreeWidgetItem *i = _treew->selectedItems().first();
82 i = (i->childCount() > 0) ? i->child(0) : i;
83 if (i)
84 emit selected(i->text(0));
87 void NLogRecent::reset()
89 if (_treew->topLevelItemCount() == 0)
90 return;
92 if (ask(this, tr("All records will be lost permanently. Really clear?"))
93 != QMessageBox::Yes)
95 return;
98 _treew->clear();
99 recent.clear();
102 } // namespace nn
104 /* vim: set ts=2 sw=2 tw=72 expandtab: */