3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "refinesearchwidget.h"
22 #include "fontutils.h"
23 #include "searchparams.h"
29 QHash<QString, QAction*>* globalActions();
32 RefineSearchWidget::RefineSearchWidget(QWidget *parent) :
37 void RefineSearchWidget::setup() {
38 static bool isSetup = false;
42 static const int spacing = 15;
43 setFont(FontUtils::medium());
45 QBoxLayout *layout = new QVBoxLayout(this);
46 layout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
47 layout->setMargin(spacing*2);
48 layout->setSpacing(spacing);
50 QString paramName = "sortBy";
51 setupLabel(tr("Sort by"), layout, paramName);
52 QToolBar *sortBar = setupBar(paramName);
53 QActionGroup* sortGroup = new QActionGroup(this);
54 QStringList sortOptions = QStringList()
60 foreach (QString actionName, sortOptions) {
61 QAction *action = new QAction(actionName, sortBar);
62 action->setCheckable(true);
63 action->setFont(FontUtils::medium());
64 action->setProperty("paramValue", i);
65 sortGroup->addAction(action);
66 sortBar->addAction(action);
71 layout->addSpacing(spacing);
72 setupLabel(tr("Date"), layout, paramName);
73 QToolBar *timeBar = setupBar(paramName);
74 QActionGroup* timeGroup = new QActionGroup(this);
75 QStringList timeSpans = QStringList()
81 foreach (QString actionName, timeSpans) {
82 QAction *action = new QAction(actionName, timeBar);
83 action->setCheckable(true);
84 action->setFont(FontUtils::medium());
85 action->setProperty("paramValue", i);
86 timeGroup->addAction(action);
87 timeBar->addAction(action);
91 paramName = "duration";
92 layout->addSpacing(spacing);
93 setupLabel(tr("Duration"), layout, paramName);
94 QToolBar *lengthBar = setupBar(paramName);
95 QActionGroup* lengthGroup = new QActionGroup(this);
96 QStringList lengthOptions = QStringList()
101 QStringList tips = QStringList()
103 << tr("Less than 4 minutes")
104 << tr("Between 4 and 20 minutes")
105 << tr("Longer than 20 minutes");
107 foreach (QString actionName, lengthOptions) {
108 QAction *action = new QAction(actionName, timeBar);
109 action->setStatusTip(tips.at(i));
110 action->setCheckable(true);
111 action->setFont(FontUtils::medium());
112 action->setProperty("paramValue", i);
113 lengthGroup->addAction(action);
114 lengthBar->addAction(action);
118 paramName = "quality";
119 layout->addSpacing(spacing);
120 setupLabel(tr("Quality"), layout, paramName);
121 QToolBar *qualityBar = setupBar(paramName);
122 QActionGroup* qualityGroup = new QActionGroup(this);
123 QStringList qualityOptions = QStringList()
125 << tr("High Definition");
128 << tr("720p or higher");
130 foreach (QString actionName, qualityOptions) {
131 QAction *action = new QAction(actionName, timeBar);
132 action->setStatusTip(tips.at(i));
133 action->setCheckable(true);
134 action->setFont(FontUtils::medium());
135 action->setProperty("paramValue", i);
136 qualityGroup->addAction(action);
137 qualityBar->addAction(action);
141 layout->addSpacing(spacing);
142 doneButton = new QPushButton(tr("Done"), this);
143 doneButton->setDefault(true);
144 doneButton->setAutoDefault(true);
145 doneButton->setFocusPolicy(Qt::StrongFocus);
146 doneButton->setFont(FontUtils::medium());
147 doneButton->setProperty("custom", true);
148 doneButton->setProperty("important", true);
149 doneButton->setProperty("big", true);
150 connect(doneButton, SIGNAL(clicked()), SLOT(doneClicked()));
151 layout->addWidget(doneButton, 0, Qt::AlignLeft);
154 void RefineSearchWidget::setupLabel(QString text, QBoxLayout *layout, QString paramName) {
155 QBoxLayout* hLayout = new QHBoxLayout();
156 hLayout->setSpacing(8);
157 hLayout->setMargin(0);
158 hLayout->setAlignment(Qt::AlignVCenter);
160 QLabel *icon = new QLabel(this);
161 icon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
162 QString resource = paramName;
164 resource = Extra::resourceName(resource);
166 QPixmap pixmap = QPixmap(":/images/search-" + resource + ".png");
167 QPixmap translucentPixmap(pixmap.size());
168 translucentPixmap.fill(Qt::transparent);
170 painter.begin(&translucentPixmap);
171 painter.setOpacity(0.5);
172 painter.drawPixmap(0, 0, pixmap);
174 icon->setPixmap(translucentPixmap);
175 hLayout->addWidget(icon);
177 QLabel *label = new QLabel(text.toUpper(), this);
178 label->setFont(FontUtils::mediumBold());
179 label->setStyleSheet("color: rgba(0, 0, 0, 128);");
180 hLayout->addWidget(label);
182 icon->setMaximumHeight(label->height());
184 layout->addLayout(hLayout);
187 QToolBar* RefineSearchWidget::setupBar(QString paramName) {
188 QToolBar* bar = new QToolBar(this);
189 bar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
190 // bar->setProperty("segmented", true);
191 bar->setFont(FontUtils::medium());
192 bar->setProperty("paramName", paramName);
193 connect(bar, SIGNAL(actionTriggered(QAction*)),
194 SLOT(actionTriggered(QAction*)));
195 bars.insert(paramName, bar);
196 layout()->addWidget(bar);
200 void RefineSearchWidget::paintEvent(QPaintEvent * /*event*/) {
201 #if defined(APP_MAC) | defined(APP_WIN)
203 if (window()->isActiveWindow()) {
204 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
206 brush = palette().window();
208 QPainter painter(this);
209 painter.fillRect(0, 0, width(), height(), brush);
213 void RefineSearchWidget::actionTriggered(QAction *action) {
214 QToolBar *bar = static_cast<QToolBar *>(sender());
216 qDebug() << __PRETTY_FUNCTION__ << "Cannot get sender";
220 QString paramName = bar->property("paramName").toString();
221 QVariant paramValue = action->property("paramValue");
223 // qDebug() << "param changed" << paramName << paramValue;
224 emit paramChanged(paramName, paramValue);
229 void RefineSearchWidget::setSearchParams(SearchParams *params) {
232 The::globalActions()->value("refine-search")->setEnabled(params);
240 bar = bars.value("sortBy");
241 action = bar->actions().at(params->sortBy());
242 if (action) action->setChecked(true);
244 bar = bars.value("duration");
245 action = bar->actions().at(params->duration());
246 if (action) action->setChecked(true);
248 bar = bars.value("time");
249 action = bar->actions().at(params->time());
250 if (action) action->setChecked(true);
252 bar = bars.value("quality");
253 action = bar->actions().at(params->quality());
254 if (action) action->setChecked(true);
256 disconnect(SIGNAL(paramChanged(QString,QVariant)));
257 connect(this, SIGNAL(paramChanged(QString,QVariant)),
258 params, SLOT(setParam(QString,QVariant)),
259 Qt::UniqueConnection);
263 doneButton->setFocus();
266 void RefineSearchWidget::doneClicked() {
267 if (dirty) emit searchRefined();