1 #include "refinesearchwidget.h"
3 #include "searchparams.h"
9 QHash<QString, QAction*>* globalActions();
12 RefineSearchWidget::RefineSearchWidget(QWidget *parent) :
17 void RefineSearchWidget::setup() {
18 static bool isSetup = false;
22 static const int spacing = 15;
23 setFont(FontUtils::medium());
25 QBoxLayout *layout = new QVBoxLayout(this);
26 layout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
27 layout->setMargin(spacing*2);
28 layout->setSpacing(spacing);
30 QString paramName = "sortBy";
31 setupLabel(tr("Sort by"), layout, paramName);
32 QToolBar *sortBar = setupBar(paramName);
33 QActionGroup* sortGroup = new QActionGroup(this);
34 QStringList sortOptions = QStringList()
40 foreach (QString actionName, sortOptions) {
41 QAction *action = new QAction(actionName, sortBar);
42 action->setCheckable(true);
43 action->setFont(FontUtils::medium());
44 action->setProperty("paramValue", i);
45 sortGroup->addAction(action);
46 sortBar->addAction(action);
51 layout->addSpacing(spacing);
52 setupLabel(tr("Date"), layout, paramName);
53 QToolBar *timeBar = setupBar(paramName);
54 QActionGroup* timeGroup = new QActionGroup(this);
55 QStringList timeSpans = QStringList()
61 foreach (QString actionName, timeSpans) {
62 QAction *action = new QAction(actionName, timeBar);
63 action->setCheckable(true);
64 action->setFont(FontUtils::medium());
65 action->setProperty("paramValue", i);
66 timeGroup->addAction(action);
67 timeBar->addAction(action);
71 paramName = "duration";
72 layout->addSpacing(spacing);
73 setupLabel(tr("Duration"), layout, paramName);
74 QToolBar *lengthBar = setupBar(paramName);
75 QActionGroup* lengthGroup = new QActionGroup(this);
76 QStringList lengthOptions = QStringList()
81 QStringList tips = QStringList()
83 << tr("Less than 4 minutes")
84 << tr("Between 4 and 20 minutes")
85 << tr("Longer than 20 minutes");
87 foreach (QString actionName, lengthOptions) {
88 QAction *action = new QAction(actionName, timeBar);
89 action->setStatusTip(tips.at(i));
90 action->setCheckable(true);
91 action->setFont(FontUtils::medium());
92 action->setProperty("paramValue", i);
93 lengthGroup->addAction(action);
94 lengthBar->addAction(action);
98 paramName = "quality";
99 layout->addSpacing(spacing);
100 setupLabel(tr("Quality"), layout, paramName);
101 QToolBar *qualityBar = setupBar(paramName);
102 QActionGroup* qualityGroup = new QActionGroup(this);
103 QStringList qualityOptions = QStringList()
105 << tr("High Definition");
108 << tr("720p or higher");
110 foreach (QString actionName, qualityOptions) {
111 QAction *action = new QAction(actionName, timeBar);
112 action->setStatusTip(tips.at(i));
113 action->setCheckable(true);
114 action->setFont(FontUtils::medium());
115 action->setProperty("paramValue", i);
116 qualityGroup->addAction(action);
117 qualityBar->addAction(action);
121 layout->addSpacing(spacing);
122 QPushButton *doneButton = new QPushButton(tr("Done"), this);
123 doneButton->setDefault(true);
124 doneButton->setFont(FontUtils::medium());
125 doneButton->setProperty("custom", true);
126 doneButton->setProperty("important", true);
127 doneButton->setProperty("big", true);
128 connect(doneButton, SIGNAL(clicked()), SLOT(doneClicked()));
129 layout->addWidget(doneButton, 0, Qt::AlignLeft);
132 void RefineSearchWidget::setupLabel(QString text, QBoxLayout *layout, QString paramName) {
133 QBoxLayout* hLayout = new QHBoxLayout();
134 hLayout->setSpacing(8);
135 hLayout->setMargin(0);
136 hLayout->setAlignment(Qt::AlignVCenter);
138 QLabel *icon = new QLabel(this);
139 icon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
140 QString resource = paramName;
142 resource = Extra::resourceName(resource);
144 QPixmap pixmap = QPixmap(":/images/search-" + resource + ".png");
145 QPixmap translucentPixmap(pixmap.size());
146 translucentPixmap.fill(Qt::transparent);
148 painter.begin(&translucentPixmap);
149 painter.setOpacity(0.5);
150 painter.drawPixmap(0, 0, pixmap);
152 icon->setPixmap(translucentPixmap);
153 hLayout->addWidget(icon);
155 QLabel *label = new QLabel(text.toUpper(), this);
156 label->setFont(FontUtils::mediumBold());
157 label->setStyleSheet("color: rgba(0, 0, 0, 128);");
158 hLayout->addWidget(label);
160 icon->setMaximumHeight(label->height());
162 layout->addLayout(hLayout);
165 QToolBar* RefineSearchWidget::setupBar(QString paramName) {
166 QToolBar* bar = new QToolBar(this);
167 bar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
168 // bar->setProperty("segmented", true);
169 bar->setFont(FontUtils::medium());
170 bar->setProperty("paramName", paramName);
171 connect(bar, SIGNAL(actionTriggered(QAction*)),
172 SLOT(actionTriggered(QAction*)));
173 bars.insert(paramName, bar);
174 layout()->addWidget(bar);
178 void RefineSearchWidget::paintEvent(QPaintEvent * /*event*/) {
179 #if defined(APP_MAC) | defined(APP_WIN)
181 if (window()->isActiveWindow()) {
182 brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
184 brush = palette().window();
186 QPainter painter(this);
187 painter.fillRect(0, 0, width(), height(), brush);
191 void RefineSearchWidget::actionTriggered(QAction *action) {
192 QToolBar *bar = static_cast<QToolBar *>(sender());
194 qDebug() << __PRETTY_FUNCTION__ << "Cannot get sender";
198 QString paramName = bar->property("paramName").toString();
199 QVariant paramValue = action->property("paramValue");
201 // qDebug() << "param changed" << paramName << paramValue;
202 emit paramChanged(paramName, paramValue);
207 void RefineSearchWidget::setSearchParams(SearchParams *params) {
210 qDebug() << (params != 0);
212 The::globalActions()->value("refine-search")->setEnabled(params);
220 bar = bars.value("sortBy");
221 action = bar->actions().at(params->sortBy());
222 if (action) action->setChecked(true);
224 bar = bars.value("duration");
225 action = bar->actions().at(params->duration());
226 if (action) action->setChecked(true);
228 bar = bars.value("time");
229 action = bar->actions().at(params->time());
230 if (action) action->setChecked(true);
232 bar = bars.value("quality");
233 action = bar->actions().at(params->quality());
234 if (action) action->setChecked(true);
236 disconnect(SIGNAL(paramChanged(QString,QVariant)));
237 connect(this, SIGNAL(paramChanged(QString,QVariant)),
238 params, SLOT(setParam(QString,QVariant)),
239 Qt::UniqueConnection);
244 void RefineSearchWidget::doneClicked() {
245 if (dirty) emit searchRefined();