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"
28 QHash<QString, QAction*>* globalActions();
31 RefineSearchWidget::RefineSearchWidget(QWidget *parent) :
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*2);
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 QStringList sortOptions = QStringList()
58 foreach (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 QStringList timeSpans = QStringList()
78 foreach (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 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 foreach (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 QStringList qualityOptions = QStringList()
120 << tr("High Definition");
123 << tr("720p or higher");
125 foreach (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 = QPixmap(":/images/search-" + resource + ".png");
159 QPixmap translucentPixmap(pixmap.size());
160 translucentPixmap.fill(Qt::transparent);
162 painter.begin(&translucentPixmap);
163 painter.setOpacity(0.5);
164 painter.drawPixmap(0, 0, pixmap);
166 icon->setPixmap(translucentPixmap);
167 hLayout->addWidget(icon);
169 QLabel *label = new QLabel(text, this);
170 label->setStyleSheet("color: rgba(0, 0, 0, 128);");
171 hLayout->addWidget(label);
173 icon->setMaximumHeight(label->height());
175 layout->addLayout(hLayout);
178 QToolBar* RefineSearchWidget::setupBar(const QString ¶mName) {
179 QToolBar* bar = new QToolBar(this);
180 bar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
181 // bar->setProperty("segmented", true);
182 bar->setProperty("paramName", paramName);
183 connect(bar, SIGNAL(actionTriggered(QAction*)), SLOT(actionTriggered(QAction*)));
184 bars.insert(paramName, bar);
185 layout()->addWidget(bar);
189 void RefineSearchWidget::actionTriggered(QAction *action) {
190 QToolBar *bar = static_cast<QToolBar *>(sender());
192 qDebug() << __PRETTY_FUNCTION__ << "Cannot get sender";
196 QString paramName = bar->property("paramName").toString();
197 QVariant paramValue = action->property("paramValue");
199 // qDebug() << "param changed" << paramName << paramValue;
200 emit paramChanged(paramName, paramValue);
205 void RefineSearchWidget::setSearchParams(SearchParams *params) {
208 The::globalActions()->value("refine-search")->setEnabled(params);
216 bar = bars.value("sortBy");
217 action = bar->actions().at(params->sortBy());
218 if (action) action->setChecked(true);
220 bar = bars.value("duration");
221 action = bar->actions().at(params->duration());
222 if (action) action->setChecked(true);
224 bar = bars.value("time");
225 action = bar->actions().at(params->time());
226 if (action) action->setChecked(true);
228 bar = bars.value("quality");
229 action = bar->actions().at(params->quality());
230 if (action) action->setChecked(true);
232 disconnect(SIGNAL(paramChanged(QString,QVariant)));
233 connect(this, SIGNAL(paramChanged(QString,QVariant)),
234 params, SLOT(setParam(QString,QVariant)),
235 Qt::UniqueConnection);
239 doneButton->setFocus();
242 void RefineSearchWidget::doneClicked() {
243 if (dirty) emit searchRefined();