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 "searchparams.h"
26 #include "iconutils.h"
27 #include "mainwindow.h"
29 RefineSearchWidget::RefineSearchWidget(QWidget *parent) :
32 // Fixes background painting in fullscreen
33 setAutoFillBackground(true);
36 void RefineSearchWidget::setup() {
37 static bool isSetup = false;
41 const int spacing = 15;
43 QBoxLayout *layout = new QVBoxLayout(this);
44 layout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
45 layout->setMargin(spacing);
46 layout->setSpacing(spacing);
48 QString paramName = "sortBy";
49 setupLabel(tr("Sort by"), layout, paramName);
50 QToolBar *sortBar = setupBar(paramName);
51 QActionGroup* sortGroup = new QActionGroup(this);
52 const QStringList sortOptions = QStringList()
58 for (const QString &actionName : sortOptions) {
59 QAction *action = new QAction(actionName, sortBar);
60 action->setCheckable(true);
61 action->setProperty("paramValue", i);
62 sortGroup->addAction(action);
63 sortBar->addAction(action);
68 layout->addSpacing(spacing);
69 setupLabel(tr("Date"), layout, paramName);
70 QToolBar *timeBar = setupBar(paramName);
71 QActionGroup* timeGroup = new QActionGroup(this);
72 const QStringList timeSpans = QStringList()
78 for (const QString &actionName : timeSpans) {
79 QAction *action = new QAction(actionName, timeBar);
80 action->setCheckable(true);
81 action->setProperty("paramValue", i);
82 timeGroup->addAction(action);
83 timeBar->addAction(action);
87 paramName = "duration";
88 layout->addSpacing(spacing);
89 setupLabel(tr("Duration"), layout, paramName);
90 QToolBar *lengthBar = setupBar(paramName);
91 QActionGroup* lengthGroup = new QActionGroup(this);
92 const QStringList lengthOptions = QStringList()
97 QStringList tips = QStringList()
99 << tr("Less than 4 minutes")
100 << tr("Between 4 and 20 minutes")
101 << tr("Longer than 20 minutes");
103 for (const QString &actionName : lengthOptions) {
104 QAction *action = new QAction(actionName, timeBar);
105 action->setStatusTip(tips.at(i));
106 action->setCheckable(true);
107 action->setProperty("paramValue", i);
108 lengthGroup->addAction(action);
109 lengthBar->addAction(action);
113 paramName = "quality";
114 layout->addSpacing(spacing);
115 setupLabel(tr("Quality"), layout, paramName);
116 QToolBar *qualityBar = setupBar(paramName);
117 QActionGroup* qualityGroup = new QActionGroup(this);
118 const QStringList qualityOptions = QStringList()
120 << tr("High Definition");
123 << tr("720p or higher");
125 for (const QString &actionName : qualityOptions) {
126 QAction *action = new QAction(actionName, timeBar);
127 action->setStatusTip(tips.at(i));
128 action->setCheckable(true);
129 action->setProperty("paramValue", i);
130 qualityGroup->addAction(action);
131 qualityBar->addAction(action);
135 layout->addSpacing(spacing);
136 doneButton = new QPushButton(tr("Done"), this);
137 doneButton->setDefault(true);
138 doneButton->setAutoDefault(true);
139 doneButton->setFocusPolicy(Qt::StrongFocus);
141 doneButton->setProperty("custom", true);
142 doneButton->setProperty("important", true);
143 doneButton->setProperty("big", true);
145 connect(doneButton, SIGNAL(clicked()), SLOT(doneClicked()));
146 layout->addWidget(doneButton, 0, Qt::AlignLeft);
149 void RefineSearchWidget::setupLabel(const QString &text, QBoxLayout *layout, const QString ¶mName) {
150 QBoxLayout* hLayout = new QHBoxLayout();
151 hLayout->setSpacing(8);
152 hLayout->setMargin(0);
153 hLayout->setAlignment(Qt::AlignVCenter);
155 QLabel *icon = new QLabel(this);
156 icon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
157 QString resource = paramName;
158 QPixmap pixmap = IconUtils::pixmap(":/images/search-" + resource + ".png");
160 QPixmap translucentPixmap(pixmap.size());
161 translucentPixmap.fill(Qt::transparent);
163 painter.begin(&translucentPixmap);
164 painter.setOpacity(0.5);
165 painter.drawPixmap(0, 0, pixmap);
168 icon->setPixmap(pixmap);
169 hLayout->addWidget(icon);
171 QLabel *label = new QLabel(text, this);
172 hLayout->addWidget(label);
174 icon->setMaximumHeight(label->height());
176 layout->addLayout(hLayout);
179 QToolBar* RefineSearchWidget::setupBar(const QString ¶mName) {
180 QToolBar* bar = new QToolBar(this);
181 bar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
182 // bar->setProperty("segmented", true);
183 bar->setProperty("paramName", paramName);
184 connect(bar, SIGNAL(actionTriggered(QAction*)), SLOT(actionTriggered(QAction*)));
185 bars.insert(paramName, bar);
186 layout()->addWidget(bar);
190 void RefineSearchWidget::actionTriggered(QAction *action) {
191 QToolBar *bar = static_cast<QToolBar *>(sender());
193 qDebug() << __PRETTY_FUNCTION__ << "Cannot get sender";
197 QString paramName = bar->property("paramName").toString();
198 QVariant paramValue = action->property("paramValue");
200 // qDebug() << "param changed" << paramName << paramValue;
201 emit paramChanged(paramName, paramValue);
206 void RefineSearchWidget::setSearchParams(SearchParams *params) {
209 MainWindow::instance()->getAction("refineSearch")->setEnabled(params);
217 bar = bars.value("sortBy");
218 action = bar->actions().at(params->sortBy());
219 if (action) action->setChecked(true);
221 bar = bars.value("duration");
222 action = bar->actions().at(params->duration());
223 if (action) action->setChecked(true);
225 bar = bars.value("time");
226 action = bar->actions().at(params->time());
227 if (action) action->setChecked(true);
229 bar = bars.value("quality");
230 action = bar->actions().at(params->quality());
231 if (action) action->setChecked(true);
233 disconnect(SIGNAL(paramChanged(QString,QVariant)));
234 connect(this, SIGNAL(paramChanged(QString,QVariant)),
235 params, SLOT(setParam(QString,QVariant)),
236 Qt::UniqueConnection);
240 doneButton->setFocus();
243 void RefineSearchWidget::doneClicked() {
244 if (dirty) emit searchRefined();