]> git.sur5r.net Git - minitube/commitdiff
SearchLineEdit refactoring
authorFlavio Tordini <flavio.tordini@gmail.com>
Mon, 24 Aug 2015 20:29:01 +0000 (22:29 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Mon, 24 Aug 2015 20:29:01 +0000 (22:29 +0200)
17 files changed:
minitube.pro
src/autocomplete.cpp
src/autocomplete.h
src/exlineedit.cpp [new file with mode: 0644]
src/exlineedit.h [new file with mode: 0644]
src/mainwindow.cpp
src/mainwindow.h
src/mediaview.cpp
src/searchlineedit.cpp
src/searchlineedit.h
src/searchview.cpp
src/searchview.h
src/searchwidget.cpp [new file with mode: 0644]
src/searchwidget.h [new file with mode: 0644]
src/segmentedcontrol.cpp
src/urllineedit.cpp [deleted file]
src/urllineedit.h [deleted file]

index 3f2d29fa3c97a0919c16794f497572fa8fb3f9f3..42053a66de919c608b1c5d2da959a6e00f8afaff 100644 (file)
@@ -36,7 +36,6 @@ include(src/qtsingleapplication/qtsingleapplication.pri)
 
 HEADERS += src/video.h \
     src/searchlineedit.h \
-    src/urllineedit.h \
     src/spacer.h \
     src/constants.h \
     src/playlistitemdelegate.h \
@@ -106,10 +105,11 @@ HEADERS += src/video.h \
     src/yt3.h \
     src/paginatedvideosource.h \
     src/compatibility/qurlqueryhelper.h \
-    src/compatibility/pathsservice.h
+    src/compatibility/pathsservice.h \
+    src/searchwidget.h \
+    src/exlineedit.h
 SOURCES += src/main.cpp \
     src/searchlineedit.cpp \
-    src/urllineedit.cpp \
     src/spacer.cpp \
     src/video.cpp \
     src/videomimedata.cpp \
@@ -176,7 +176,9 @@ SOURCES += src/main.cpp \
     src/ytchannel.cpp \
     src/yt3.cpp \
     src/paginatedvideosource.cpp \
-    src/compatibility/pathsservice.cpp
+    src/compatibility/pathsservice.cpp \
+    src/exlineedit.cpp \
+    src/searchwidget.cpp
 RESOURCES += resources.qrc
 DESTDIR = build/target/
 OBJECTS_DIR = build/obj/
index 84c11dec3eb802969d695803875bd076f2ceef1f..0a78c9cc96d0645d9cbeed2ca6b24b6c2f57134f 100644 (file)
@@ -46,14 +46,14 @@ QDebug operator<<(QDebug str, const QEvent * ev) {
 }
 #endif
 
-AutoComplete::AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit):
-    QObject(buddy), buddy(buddy), lineEdit(lineEdit), enabled(true), suggester(0), itemHovering(false) {
+AutoComplete::AutoComplete(SearchWidget *buddy, QLineEdit *lineEdit):
+    QObject(lineEdit), buddy(buddy), lineEdit(lineEdit), enabled(true), suggester(0), itemHovering(false) {
 
     popup = new QListWidget();
     popup->setWindowFlags(Qt::Popup);
-    popup->setFocusProxy(buddy);
+    popup->setFocusProxy(buddy->toWidget());
     popup->installEventFilter(this);
-    buddy->window()->installEventFilter(this);
+    buddy->toWidget()->window()->installEventFilter(this);
     popup->setMouseTracking(true);
 
     // style
@@ -71,7 +71,7 @@ AutoComplete::AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit):
     timer->setSingleShot(true);
     timer->setInterval(500);
     connect(timer, SIGNAL(timeout()), SLOT(suggest()));
-    connect(buddy, SIGNAL(textEdited(QString)), timer, SLOT(start()));
+    connect(buddy->toWidget(), SIGNAL(textEdited(QString)), timer, SLOT(start()));
 }
 
 bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) {
@@ -128,7 +128,7 @@ bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) {
                 popup->setCurrentItem(0);
                 popup->clearSelection();
                 buddy->setText(originalText);
-                buddy->setFocus();
+                buddy->toWidget()->setFocus();
                 consumed = true;
             }
             break;
@@ -155,6 +155,7 @@ bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) {
 }
 
 void AutoComplete::showSuggestions(const QList<Suggestion *> &suggestions) {
+    qDebug() << __PRETTY_FUNCTION__;
     if (suggestions.isEmpty()) {
         hideSuggestions();
         return;
@@ -173,7 +174,7 @@ void AutoComplete::showSuggestions(const QList<Suggestion *> &suggestions) {
     for (int i = 0; i < suggestions.count(); ++i)
         h += popup->sizeHintForRow(i);
 
-    popup->resize(buddy->width(), h);
+    popup->resize(buddy->toWidget()->width(), h);
     adjustPosition();
     popup->setUpdatesEnabled(true);
 
@@ -231,12 +232,12 @@ void AutoComplete::suggestionsReady(const QList<Suggestion *> &suggestions) {
     qDeleteAll(this->suggestions);
     this->suggestions = suggestions;
     if (!enabled) return;
-    if (!buddy->hasFocus()) return;
+    if (!buddy->toWidget()->hasFocus() && buddy->toWidget()->isVisible()) return;
     showSuggestions(suggestions);
 }
 
 void AutoComplete::adjustPosition() {
-    popup->move(buddy->mapToGlobal(QPoint(0, buddy->height())));
+    popup->move(buddy->toWidget()->mapToGlobal(QPoint(0, buddy->toWidget()->height())));
 }
 
 void AutoComplete::enableItemHovering() {
@@ -255,7 +256,7 @@ void AutoComplete::hideSuggestions() {
         buddy->setText(originalText);
         originalText.clear();
     }
-    buddy->setFocus();
+    buddy->toWidget()->setFocus();
     timer->stop();
 }
 
index df6089b389881220702fa59b73cc76ee9ff30138..25a632dcb7eae0ffcb1a189874f23f0dd11151b0 100644 (file)
@@ -24,7 +24,7 @@ $END_LICENSE */
 
 class Suggester;
 class Suggestion;
-class SearchLineEdit;
+class SearchWidget;
 
 QT_FORWARD_DECLARE_CLASS(QListWidget)
 QT_FORWARD_DECLARE_CLASS(QListWidgetItem)
@@ -35,7 +35,7 @@ class AutoComplete : public QObject {
     Q_OBJECT
 
 public:
-    AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit);
+    AutoComplete(SearchWidget *buddy, QLineEdit *lineEdit);
     void setSuggester(Suggester* suggester);
     QListWidget* getPopup() { return popup; }
     void preventSuggest();
@@ -61,7 +61,7 @@ private:
     void showSuggestions(const QList<Suggestion*> &suggestions);
     void hideSuggestions();
 
-    SearchLineEdit *buddy;
+    SearchWidget *buddy;
     QLineEdit *lineEdit;
     QString originalText;
     QListWidget *popup;
diff --git a/src/exlineedit.cpp b/src/exlineedit.cpp
new file mode 100644 (file)
index 0000000..2742afb
--- /dev/null
@@ -0,0 +1,186 @@
+#include "exlineedit.h"
+#include "iconutils.h"
+
+ClearButton::ClearButton(QWidget *parent) : QAbstractButton(parent), hovered(false), mousePressed(false) {
+    setCursor(Qt::ArrowCursor);
+    setToolTip(tr("Clear"));
+    setVisible(false);
+    setFocusPolicy(Qt::NoFocus);
+}
+
+void ClearButton::paintEvent(QPaintEvent *e) {
+    Q_UNUSED(e);
+    QPainter painter(this);
+    const int h = height();
+    int iconSize = 16;
+    if (h > 30) iconSize = 22;
+    QIcon::Mode iconMode = QIcon::Normal;
+    if (mousePressed) iconMode = QIcon::Active;
+    QPixmap p = IconUtils::icon("edit-clear").pixmap(iconSize, iconSize, iconMode);
+    int x = (width() - p.width()) / 2;
+    int y = (h - p.height()) / 2;
+    painter.drawPixmap(x, y, p);
+}
+
+void ClearButton::textChanged(const QString &text) {
+    setVisible(!text.isEmpty());
+}
+
+void ClearButton::enterEvent(QEvent *e) {
+    Q_UNUSED(e);
+    hovered = true;
+}
+
+void ClearButton::leaveEvent(QEvent *e) {
+    Q_UNUSED(e);
+    hovered = false;
+}
+
+void ClearButton::mousePressEvent(QMouseEvent *e) {
+    Q_UNUSED(e);
+    mousePressed = true;
+}
+
+void ClearButton::mouseReleaseEvent(QMouseEvent *e) {
+    Q_UNUSED(e);
+    mousePressed = false;
+}
+
+ExLineEdit::ExLineEdit(QWidget *parent)
+    : QWidget(parent)
+    , m_leftWidget(0)
+    , m_lineEdit(new QLineEdit(this))
+    , m_clearButton(new ClearButton(this)) {
+    setFocusPolicy(m_lineEdit->focusPolicy());
+    setAttribute(Qt::WA_InputMethodEnabled);
+    setSizePolicy(m_lineEdit->sizePolicy());
+    setBackgroundRole(m_lineEdit->backgroundRole());
+    setMouseTracking(true);
+    setAcceptDrops(true);
+    setAttribute(Qt::WA_MacShowFocusRect, true);
+    QPalette p = m_lineEdit->palette();
+    setPalette(p);
+
+    // line edit
+    m_lineEdit->setFrame(false);
+    m_lineEdit->setFocusProxy(this);
+    m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
+    m_lineEdit->setStyleSheet("background:transparent");
+    QPalette clearPalette = m_lineEdit->palette();
+    clearPalette.setBrush(QPalette::Base, QBrush(Qt::transparent));
+    m_lineEdit->setPalette(clearPalette);
+
+    // clearButton
+    connect(m_clearButton, SIGNAL(clicked()), m_lineEdit, SLOT(clear()));
+    connect(m_lineEdit, SIGNAL(textChanged(const QString&)), m_clearButton, SLOT(textChanged(const QString&)));
+}
+
+void ExLineEdit::setFont(const QFont &font) {
+    m_lineEdit->setFont(font);
+    updateGeometries();
+}
+
+void ExLineEdit::setLeftWidget(QWidget *widget) {
+    m_leftWidget = widget;
+}
+
+QWidget *ExLineEdit::leftWidget() const {
+    return m_leftWidget;
+}
+
+void ExLineEdit::clear() {
+    m_lineEdit->clear();
+}
+
+QString ExLineEdit::text() {
+    return m_lineEdit->text();
+}
+
+void ExLineEdit::resizeEvent(QResizeEvent *e) {
+    Q_ASSERT(m_leftWidget);
+    updateGeometries();
+    QWidget::resizeEvent(e);
+}
+
+void ExLineEdit::updateGeometries() {
+    QStyleOptionFrameV2 panel;
+    initStyleOption(&panel);
+    QRect rect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
+
+    int padding = 3;
+    // int height = rect.height() + padding*2;
+    int width = rect.width();
+
+    // int m_leftWidgetHeight = m_leftWidget->height();
+    m_leftWidget->setGeometry(rect.x() + 2,          0,
+                              m_leftWidget->width(), m_leftWidget->height());
+
+    int clearButtonWidth = this->height();
+    m_lineEdit->setGeometry(m_leftWidget->x() + m_leftWidget->width(),        padding,
+                            width - clearButtonWidth - m_leftWidget->width(), this->height() - padding*2);
+
+    m_clearButton->setGeometry(this->width() - clearButtonWidth, 0,
+                               clearButtonWidth, this->height());
+}
+
+void ExLineEdit::initStyleOption(QStyleOptionFrameV2 *option) const {
+    option->initFrom(this);
+    option->rect = contentsRect();
+    option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this);
+    option->midLineWidth = 0;
+    option->state |= QStyle::State_Sunken;
+    if (m_lineEdit->isReadOnly())
+        option->state |= QStyle::State_ReadOnly;
+#ifdef QT_KEYPAD_NAVIGATION
+    if (hasEditFocus())
+        option->state |= QStyle::State_HasEditFocus;
+#endif
+    option->features = QStyleOptionFrameV2::None;
+}
+
+QSize ExLineEdit::sizeHint() const {
+    m_lineEdit->setFrame(true);
+    QSize size = m_lineEdit->sizeHint();
+    m_lineEdit->setFrame(false);
+    size = size + QSize(3, 3);
+    return size;
+}
+
+void ExLineEdit::focusInEvent(QFocusEvent *e) {
+    m_lineEdit->event(e);
+    QWidget::focusInEvent(e);
+}
+
+void ExLineEdit::focusOutEvent(QFocusEvent *e) {
+    m_lineEdit->event(e);
+
+    if (m_lineEdit->completer()) {
+        connect(m_lineEdit->completer(), SIGNAL(activated(QString)),
+                         m_lineEdit, SLOT(setText(QString)));
+        connect(m_lineEdit->completer(), SIGNAL(highlighted(QString)),
+                         m_lineEdit, SLOT(_q_completionHighlighted(QString)));
+    }
+    QWidget::focusOutEvent(e);
+}
+
+void ExLineEdit::keyPressEvent(QKeyEvent *e) {
+    if (e->key() == Qt::Key_Escape && !m_lineEdit->text().isEmpty()) {
+        m_lineEdit->clear();
+    }
+    m_lineEdit->event(e);
+    QWidget::keyPressEvent(e);
+}
+
+bool ExLineEdit::event(QEvent *e) {
+    if (e->type() == QEvent::ShortcutOverride || e->type() == QEvent::InputMethod)
+        m_lineEdit->event(e);
+    return QWidget::event(e);
+}
+
+void ExLineEdit::paintEvent(QPaintEvent *e) {
+    Q_UNUSED(e);
+    QPainter p(this);
+    QStyleOptionFrameV2 panel;
+    initStyleOption(&panel);
+    style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
+}
diff --git a/src/exlineedit.h b/src/exlineedit.h
new file mode 100644 (file)
index 0000000..228b781
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef EXLINEEDIT_H
+#define EXLINEEDIT_H
+
+#include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
+
+class ClearButton : public QAbstractButton {
+
+    Q_OBJECT
+
+public:
+    ClearButton(QWidget *parent = 0);
+
+public slots:
+    void textChanged(const QString &text);
+
+protected:
+    void paintEvent(QPaintEvent *e);
+    void enterEvent(QEvent *e);
+    void leaveEvent(QEvent *e);
+    void mousePressEvent(QMouseEvent *e);
+    void mouseReleaseEvent(QMouseEvent *e);
+
+private:
+    bool hovered;
+    bool mousePressed;
+};
+
+class ExLineEdit : public QWidget {
+
+    Q_OBJECT
+
+public:
+    ExLineEdit(QWidget *parent = 0);
+    QLineEdit *lineEdit() const { return m_lineEdit; }
+    void setLeftWidget(QWidget *widget);
+    QWidget *leftWidget() const;
+    void clear();
+    QString text();
+    QSize sizeHint() const;
+    void updateGeometries();
+    void setFont(const QFont &font);
+
+protected:
+    void focusInEvent(QFocusEvent *e);
+    void focusOutEvent(QFocusEvent *e);
+    void keyPressEvent(QKeyEvent *e);
+    void paintEvent(QPaintEvent *e);
+    void resizeEvent(QResizeEvent *e);
+    bool event(QEvent *e);
+    void initStyleOption(QStyleOptionFrameV2 *option) const;
+
+    QWidget *m_leftWidget;
+    QLineEdit *m_lineEdit;
+    ClearButton *m_clearButton;
+};
+
+#endif // EXLINEEDIT_H
+
index cfafa38af2aa3b1bfc7d0b186f6104f72887970b..cecefd4e0af6fcd0a1c0e4edece612ed6573755f 100644 (file)
@@ -47,7 +47,7 @@ $END_LICENSE */
 #include "ytsuggester.h"
 #include "updatechecker.h"
 #include "temporary.h"
-#ifdef APP_MAC_SEARCHFIELD
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
 #include "searchlineedit_mac.h"
 #else
 #include "searchlineedit.h"
@@ -754,11 +754,12 @@ void MainWindow::createToolBars() {
     volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
 #endif
 
-#ifdef APP_MAC_SEARCHFIELD
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
     SearchWrapper* searchWrapper = new SearchWrapper(this);
     toolbarSearch = searchWrapper->getSearchLineEdit();
 #else
     toolbarSearch = new SearchLineEdit(this);
+    qDebug() << "Qt SearchLineEdit" << toolbarSearch;
 #endif
     toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
     toolbarSearch->setSuggester(new YTSuggester(this));
@@ -769,7 +770,6 @@ void MainWindow::createToolBars() {
     // Add widgets to toolbar
 
 #ifdef APP_MAC_QMACTOOLBAR
-    searchWrapper->hide();
     currentTime->hide();
     toolbarSearch->hide();
     volumeSlider->hide();
@@ -827,7 +827,7 @@ void MainWindow::createToolBars() {
 
     mainToolBar->addWidget(new Spacer());
 
-#ifdef APP_MAC_SEARCHFIELD
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
     mainToolBar->addWidget(searchWrapper);
 #else
     mainToolBar->addWidget(toolbarSearch);
@@ -841,7 +841,7 @@ void MainWindow::createStatusBar() {
     statusToolBar = new QToolBar(this);
     statusToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     statusToolBar->setIconSize(QSize(16, 16));
-    statusToolBar->addAction(The::globalActions()->value("downloads"));
+    // statusToolBar->addAction(The::globalActions()->value("downloads"));
 
     regionAction = new QAction(this);
     regionAction->setStatusTip(tr("Choose your content location"));
@@ -879,12 +879,13 @@ void MainWindow::showActionInStatusBar(QAction* action, bool show) {
 #endif
     if (show) {
         statusToolBar->insertAction(statusToolBar->actions().first(), action);
-        if (statusBar()->isHidden())
+        if (statusBar()->isHidden() && !m_fullscreen)
             setStatusBarVisibility(true);
     } else {
         statusToolBar->removeAction(action);
         if (statusBar()->isVisible() && !needStatusBar())
-            setStatusBarVisibility(false);
+            if (m_fullscreen && views->currentWidget() == mediaView)
+                setStatusBarVisibility(false);
     }
 }
 
@@ -910,12 +911,12 @@ void MainWindow::readSettings() {
         int w = qMin(2000, desktopSize.width());
         int h = qMin(w / 3, desktopSize.height());
         setGeometry(
-            QStyle::alignedRect(
-                Qt::LeftToRight,
-                Qt::AlignTop,
-                QSize(w, h),
-                desktopSize)
-            );
+                    QStyle::alignedRect(
+                        Qt::LeftToRight,
+                        Qt::AlignTop,
+                        QSize(w, h),
+                        desktopSize)
+                    );
     }
     const VideoDefinition& firstDefinition = VideoDefinition::getDefinitions().first();
     setDefinitionMode(settings.value("definition", firstDefinition.getName()).toString());
@@ -1190,6 +1191,9 @@ void MainWindow::resizeEvent(QResizeEvent*e) {
             updateUIForFullscreen();
         }
     }
+#endif
+#ifdef APP_MAC_QMACTOOLBAR
+    toolbarSearch->move(width() - toolbarSearch->width() - 13, -38);
 #endif
     adjustMessageLabelPosition();
 }
@@ -1729,8 +1733,7 @@ void MainWindow::simpleUpdateDialog(const QString &version) {
 }
 
 bool MainWindow::needStatusBar() {
-    // 1 fixed action: downloadAction
-    return statusToolBar->actions().size() > 1;
+    return !statusToolBar->actions().isEmpty();
 }
 
 void MainWindow::adjustMessageLabelPosition() {
index 9cd0b4b46975542b1a5a69773220c132d894e408..6cccabdb343f2401797d54ab4a93175d40e40bb0 100644 (file)
@@ -65,6 +65,8 @@ public:
     MediaView* getMediaView() { return mediaView; }
     QToolButton* getRegionButton() { return regionButton; }
     QAction* getRegionAction() { return regionAction; }
+    SearchLineEdit *getToolbarSearch() { return toolbarSearch; }
+
     void showActionInStatusBar(QAction*, bool show);
     void setStatusBarVisibility(bool show);
     void adjustStatusBarVisibility();
index 9130394754d1fe2ed50729c83cf31decbbf67da3..332753416f6984fafe20799359e1ae936635676d 100644 (file)
@@ -843,7 +843,7 @@ void MediaView::downloadVideo() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     DownloadManager::instance()->addItem(video);
-    The::globalActions()->value("downloads")->setVisible(true);
+    MainWindow::instance()->showActionInStatusBar(The::globalActions()->value("downloads"), true);
     QString message = tr("Downloading %1").arg(video->title());
     MainWindow::instance()->showMessage(message);
 }
index dc5115c55f877f559978d1a04a2ed8f01350ac4f..1f9fd3f65bc02df1f917b445b7eca9f77f6b34c8 100644 (file)
@@ -1,72 +1,17 @@
 #include "searchlineedit.h"
-
-#include <QPainter>
-#include <QMouseEvent>
-#include <QMenu>
-#include <QStyle>
-#include <QStyleOptionFrameV2>
-
 #include "autocomplete.h"
 #include "iconutils.h"
 
-ClearButton::ClearButton(QWidget *parent) : QAbstractButton(parent), hovered(false), mousePressed(false) {
-    setCursor(Qt::ArrowCursor);
-    setToolTip(tr("Clear"));
-    setVisible(false);
-    setFocusPolicy(Qt::NoFocus);
-}
-
-void ClearButton::paintEvent(QPaintEvent *e) {
-    Q_UNUSED(e);
-    QPainter painter(this);
-    const int h = height();
-    int iconSize = 16;
-    if (h > 30) iconSize = 22;
-    QIcon::Mode iconMode = QIcon::Normal;
-    if (mousePressed) iconMode = QIcon::Active;
-    QPixmap p = IconUtils::icon("edit-clear").pixmap(iconSize, iconSize, iconMode);
-    // QPixmap p = IconUtils::tintedIcon("edit-clear", Qt::black, QSize(iconSize, iconSize)).pixmap(iconSize, iconSize, iconMode);
-    int x = (width() - p.width()) / 2;
-    int y = (h - p.height()) / 2;
-    painter.drawPixmap(x, y, p);
-}
-
-void ClearButton::textChanged(const QString &text) {
-    setVisible(!text.isEmpty());
-}
-
-void ClearButton::enterEvent(QEvent *e) {
-    Q_UNUSED(e);
-    hovered = true;
-}
-
-void ClearButton::leaveEvent(QEvent *e) {
-    Q_UNUSED(e);
-    hovered = false;
-}
-
-void ClearButton::mousePressEvent(QMouseEvent *e) {
-    Q_UNUSED(e);
-    mousePressed = true;
-}
-
-void ClearButton::mouseReleaseEvent(QMouseEvent *e) {
-    Q_UNUSED(e);
-    mousePressed = false;
-}
-
-/*
-    Search icon on the left hand side of the search widget
-    When a menu is set a down arrow appears
- */
 class SearchButton : public QAbstractButton {
+
 public:
     SearchButton(QWidget *parent = 0);
-    void paintEvent(QPaintEvent *event);
     QMenu *m_menu;
 
 protected:
-    void mousePressEvent(QMouseEvent *event);
+    void paintEvent(QPaintEvent *e);
+    void mousePressEvent(QMouseEvent *e);
+
 };
 
 SearchButton::SearchButton(QWidget *parent)
@@ -77,20 +22,20 @@ SearchButton::SearchButton(QWidget *parent)
     setFocusPolicy(Qt::NoFocus);
 }
 
-void SearchButton::mousePressEvent(QMouseEvent *event) {
-    if (m_menu && event->button() == Qt::LeftButton) {
+void SearchButton::mousePressEvent(QMouseEvent *e) {
+    if (m_menu && e->button() == Qt::LeftButton) {
         QWidget *p = parentWidget();
         if (p) {
             QPoint r = p->mapToGlobal(QPoint(0, p->height()));
             m_menu->exec(QPoint(r.x() + height() / 2, r.y()));
         }
-        event->accept();
+        e->accept();
     }
-    QAbstractButton::mousePressEvent(event);
+    QAbstractButton::mousePressEvent(e);
 }
 
-void SearchButton::paintEvent(QPaintEvent *event) {
-    Q_UNUSED(event);
+void SearchButton::paintEvent(QPaintEvent *e) {
+    Q_UNUSED(e);
     QPainter painter(this);
     const int h = height();
     int iconSize = 16;
@@ -101,17 +46,10 @@ void SearchButton::paintEvent(QPaintEvent *event) {
     painter.drawPixmap(x, y, p);
 }
 
-/*
-    SearchLineEdit is an enhanced QLineEdit
-    - A Search icon on the left with optional menu
-    - When there is no text and doesn't have focus an "inactive text" is displayed
-    - When there is text a clear button is displayed on the right hand side
- */
-SearchLineEdit::SearchLineEdit(QWidget *parent) : ExLineEdit(parent),
-searchButton(new SearchButton(this)) {
-    connect(lineEdit(), SIGNAL(textChanged(const QString &)), SIGNAL(textChanged(const QString &)));
-    connect(lineEdit(), SIGNAL(textEdited(const QString &)), SIGNAL(textEdited(const QString &)));
-    connect(lineEdit(), SIGNAL(returnPressed()), SLOT(returnPressed()));
+SearchLineEdit::SearchLineEdit(QWidget *parent) : ExLineEdit(parent), searchButton(new SearchButton(this)) {
+    connect(m_lineEdit, SIGNAL(textChanged(const QString &)), SIGNAL(textChanged(const QString &)));
+    connect(m_lineEdit, SIGNAL(textEdited(const QString &)), SIGNAL(textEdited(const QString &)));
+    connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(returnPressed()));
 
     setLeftWidget(searchButton);
     inactiveText = tr("Search");
@@ -124,27 +62,27 @@ searchButton(new SearchButton(this)) {
     connect(autoComplete, SIGNAL(suggestionAccepted(Suggestion*)), SIGNAL(suggestionAccepted(Suggestion*)));
 }
 
-void SearchLineEdit::paintEvent(QPaintEvent *event) {
-    if (lineEdit()->text().isEmpty() && !hasFocus() && !inactiveText.isEmpty()) {
-        ExLineEdit::paintEvent(event);
+void SearchLineEdit::paintEvent(QPaintEvent *e) {
+    if (m_lineEdit->text().isEmpty() && !hasFocus() && !inactiveText.isEmpty()) {
+        ExLineEdit::paintEvent(e);
         QStyleOptionFrameV2 panel;
         initStyleOption(&panel);
         QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
         QFontMetrics fm = fontMetrics();
-        int horizontalMargin = lineEdit()->x();
+        int horizontalMargin = m_lineEdit->x();
         QRect lineRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2,
                        r.width() - 2 * horizontalMargin, fm.height());
         QPainter painter(this);
         painter.setPen(palette().brush(QPalette::Disabled, QPalette::Text).color());
-        painter.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, inactiveText);
+        painter.drawText(lineRect, Qt::AlignLeft | Qt::AlignVCenter, inactiveText);
     } else {
-        ExLineEdit::paintEvent(event);
+        ExLineEdit::paintEvent(e);
     }
 }
 
-void SearchLineEdit::resizeEvent(QResizeEvent *event) {
+void SearchLineEdit::resizeEvent(QResizeEvent *e) {
     updateGeometries();
-    ExLineEdit::resizeEvent(event);
+    ExLineEdit::resizeEvent(e);
 }
 
 void SearchLineEdit::updateGeometries() {
@@ -159,6 +97,14 @@ void SearchLineEdit::setInactiveText(const QString &text) {
     inactiveText = text;
 }
 
+void SearchLineEdit::setText(const QString &text) {
+    m_lineEdit->setText(text);
+}
+
+AutoComplete *SearchLineEdit::getAutoComplete() {
+    return autoComplete;
+}
+
 void SearchLineEdit::setMenu(QMenu *menu) {
     if (searchButton->m_menu)
         searchButton->m_menu->deleteLater();
@@ -176,9 +122,10 @@ QMenu *SearchLineEdit::menu() const {
 }
 
 void SearchLineEdit::returnPressed() {
-    if (!lineEdit()->text().isEmpty()) {
+    QString text = m_lineEdit->text().simplified();
+    if (!text.isEmpty()) {
         autoComplete->preventSuggest();
-        emit search(lineEdit()->text());
+        emit search(text);
     }
 }
 
@@ -190,7 +137,28 @@ void SearchLineEdit::preventSuggest() {
     autoComplete->preventSuggest();
 }
 
-void SearchLineEdit::focusInEvent(QFocusEvent *event) {
-    ExLineEdit::focusInEvent(event);
+void SearchLineEdit::selectAll() {
+    m_lineEdit->selectAll();
+}
+
+void SearchLineEdit::setSuggester(Suggester *suggester) {
+    autoComplete->setSuggester(suggester);
+}
+
+void SearchLineEdit::focusInEvent(QFocusEvent *e) {
+    ExLineEdit::focusInEvent(e);
     enableSuggest();
 }
+
+void SearchLineEdit::emitTextChanged(const QString &text) {
+    autoComplete->enableSuggest();
+    emit textEdited(text);
+}
+
+QString SearchLineEdit::text() {
+    return m_lineEdit->text();
+}
+
+QLineEdit *SearchLineEdit::getLineEdit() {
+    return m_lineEdit;
+}
index 83405d06c330bdfa7c4cde3f5ad7fff893c631a1..81a1947e63291499211e7fd5de27b4828fcd9497 100644 (file)
@@ -1,49 +1,39 @@
 #ifndef SEARCHLINEEDIT_H
 #define SEARCHLINEEDIT_H
 
-#include "urllineedit.h"
-#include "autocomplete.h"
+#include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
 
-#include <QLineEdit>
-#include <QAbstractButton>
-
-QT_BEGIN_NAMESPACE
-class QMenu;
-QT_END_NAMESPACE
+#include "exlineedit.h"
+#include "searchwidget.h"
 
 class SearchButton;
 class Suggester;
+class AutoComplete;
 
-/*
-    Clear button on the right hand side of the search widget.
-    Hidden by default
- */
-class ClearButton : public QAbstractButton {
+class SearchLineEdit : public ExLineEdit, public SearchWidget {
 
     Q_OBJECT
 
 public:
-    ClearButton(QWidget *parent = 0);
-    void paintEvent(QPaintEvent *e);
+    SearchLineEdit(QWidget *parent = 0);
+    QMenu *menu() const;
+    void setMenu(QMenu *menu);
+    void enableSuggest();
+    void preventSuggest();
+    void selectAll();
+    void setSuggester(Suggester *suggester);
+    void setInactiveText(const QString &text);
+    void setText(const QString &text);
+    AutoComplete *getAutoComplete();
+    void emitTextChanged(const QString &text);
+    QString text();
+    QLineEdit *getLineEdit();
 
 public slots:
-    void textChanged(const QString &text);
-
-protected:
-    void enterEvent(QEvent *e);
-    void leaveEvent(QEvent *e);
-
-    void mousePressEvent(QMouseEvent *e);
-    void mouseReleaseEvent(QMouseEvent *e);
-
-private:
-    bool hovered;
-    bool mousePressed;
-};
-
-class SearchLineEdit : public ExLineEdit {
-
-    Q_OBJECT
+    void returnPressed();
 
 signals:
     void textChanged(const QString &text);
@@ -51,27 +41,11 @@ signals:
     void search(const QString &text);
     void suggestionAccepted(Suggestion *suggestion);
 
-public:
-    SearchLineEdit(QWidget *parent = 0);
-
-    void setInactiveText(const QString &text);
-
-    QMenu *menu() const;
-    void setMenu(QMenu *menu);
-    void updateGeometries();
-    void enableSuggest();
-    void preventSuggest();
-    void selectAll() { lineEdit()->selectAll(); }
-    void setSuggester(Suggester *suggester) { autoComplete->setSuggester(suggester); }
-    void setText(const QString &text) { lineEdit()->setText(text); }
-
 protected:
-    void resizeEvent(QResizeEvent *event);
-    void paintEvent(QPaintEvent *event);
-    void focusInEvent(QFocusEvent *event);
-
-private slots:
-    void returnPressed();
+    void updateGeometries();
+    void resizeEvent(QResizeEvent *e);
+    void paintEvent(QPaintEvent *e);
+    void focusInEvent(QFocusEvent *e);
 
 private:
     SearchButton *searchButton;
index d09c51e3ba749f194c1522c91992acd20ded9373..ec5829511df93dad736b665f057f2358bf6a0f98 100644 (file)
@@ -104,10 +104,11 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     QBoxLayout *tipLayout = new QHBoxLayout();
     tipLayout->setSpacing(10);
 
+    const QFont &biggerFont = FontUtils::big();
+
     //: "Enter", as in "type". The whole phrase says: "Enter a keyword to start watching videos"
     QLabel *tipLabel = new QLabel(tr("Enter"), this);
 #ifndef APP_MAC
-    const QFont &biggerFont = FontUtils::big();
     tipLabel->setFont(biggerFont);
 #endif
     tipLayout->addWidget(tipLabel);
@@ -133,19 +134,23 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     QHBoxLayout *searchLayout = new QHBoxLayout();
     searchLayout->setAlignment(Qt::AlignVCenter);
 
+#ifdef APP_MAC_SEARCHFIELD
+    queryEdit = new SearchLineEditMac(this);
+#else
     queryEdit = new SearchLineEdit(this);
-#ifndef APP_MAC_SEARCHFIELD
-    queryEdit->setFont(biggerFont);
+    queryEdit->toWidget()->setFont(biggerFont);
 #endif
-    connect(queryEdit, SIGNAL(search(const QString&)), SLOT(watch(const QString&)));
-    connect(queryEdit, SIGNAL(textEdited(const QString &)), SLOT(textChanged(const QString &)));
-    connect(queryEdit, SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
+
+    qDebug() << "queryEdit->toWidget()" << (queryEdit->toWidget() == 0) << queryEdit->toWidget();
+    connect(queryEdit->toWidget(), SIGNAL(search(const QString&)), SLOT(watch(const QString&)));
+    connect(queryEdit->toWidget(), SIGNAL(textEdited(const QString &)), SLOT(textChanged(const QString &)));
+    connect(queryEdit->toWidget(), SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
 
     youtubeSuggest = new YTSuggester(this);
     channelSuggest = new ChannelSuggest(this);
     searchTypeChanged(0);
 
-    searchLayout->addWidget(queryEdit);
+    searchLayout->addWidget(queryEdit->toWidget());
     searchLayout->addSpacing(10);
 
     watchButton = new QPushButton(tr("Watch"), this);
@@ -204,7 +209,7 @@ void SearchView::appear() {
     queryEdit->selectAll();
     queryEdit->enableSuggest();
 
-    if (!queryEdit->hasFocus()) queryEdit->setFocus();
+    if (!queryEdit->toWidget()->hasFocus()) queryEdit->toWidget()->setFocus();
 }
 
 void SearchView::disappear() {
@@ -249,7 +254,7 @@ void SearchView::updateRecentKeywords() {
                                        + display + "</a>", this);
         itemLabel->setAttribute(Qt::WA_DeleteOnClose);
         itemLabel->setProperty("recentItem", true);
-        itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
+        itemLabel->setMaximumWidth(queryEdit->toWidget()->width() + watchButton->width());
         // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
         // Make links navigable with the keyboard too
         itemLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);
@@ -291,7 +296,7 @@ void SearchView::updateRecentChannels() {
                                        + display + "</a>", this);
         itemLabel->setAttribute(Qt::WA_DeleteOnClose);
         itemLabel->setProperty("recentItem", true);
-        itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
+        itemLabel->setMaximumWidth(queryEdit->toWidget()->width() + watchButton->width());
         // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
         // Make links navigable with the keyboard too
         itemLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);
@@ -316,7 +321,7 @@ void SearchView::watch(const QString &query) {
 
     // check for empty query
     if (q.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -336,7 +341,7 @@ void SearchView::watch(const QString &query) {
 
 void SearchView::watchChannel(const QString &channelId) {
     if (channelId.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -358,7 +363,7 @@ void SearchView::watchKeywords(const QString &query) {
 
     // check for empty query
     if (query.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -402,7 +407,7 @@ void SearchView::searchTypeChanged(int index) {
         queryEdit->setSuggester(channelSuggest);
     }
     queryEdit->selectAll();
-    queryEdit->setFocus();
+    queryEdit->toWidget()->setFocus();
 }
 
 void SearchView::suggestionAccepted(Suggestion *suggestion) {
index e8751a61904f01cdf22c28c974fdcab501868cb7..568ffbe787a518baf873196a6f64f5c6c06eaf5e 100644 (file)
@@ -27,7 +27,7 @@ $END_LICENSE */
 #endif
 #include "view.h"
 
-class SearchLineEdit;
+class SearchWidget;
 class SearchParams;
 class YTSuggester;
 class ChannelSuggest;
@@ -66,7 +66,7 @@ private:
     ChannelSuggest *channelSuggest;
 
     QComboBox *typeCombo;
-    SearchLineEdit *queryEdit;
+    SearchWidget *queryEdit;
     QLabel *recentKeywordsLabel;
     QBoxLayout *recentKeywordsLayout;
     QLabel *recentChannelsLabel;
diff --git a/src/searchwidget.cpp b/src/searchwidget.cpp
new file mode 100644 (file)
index 0000000..88a7e9d
--- /dev/null
@@ -0,0 +1,18 @@
+#include "searchwidget.h"
+
+/*
+SearchWidget::SearchWidget(QWidget *parent, SearchWidgetInterface *interface) : QWidget(parent), interface(interface) {
+    QLayout *l = new QVBoxLayout(this);
+    l->setMargin(0);
+    QWidget *w = qobject_cast<QWidget*>(interface);
+    l->addWidget(w);
+}
+
+QMenu *SearchWidget::menu() const {
+    return interface->menu();
+}
+
+void SearchWidget::setMenu(QMenu *menu) {
+    interface->setMenu(menu);
+}
+*/
diff --git a/src/searchwidget.h b/src/searchwidget.h
new file mode 100644 (file)
index 0000000..4ab9cd0
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef SEARCHWIDGET
+#define SEARCHWIDGET
+
+#include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
+
+class SearchButton;
+class Suggester;
+class Suggestion;
+class AutoComplete;
+
+class SearchWidget {
+
+public:
+    virtual QMenu *menu() const = 0;
+    virtual void setMenu(QMenu *menu) = 0;
+    virtual void enableSuggest() = 0;
+    virtual void preventSuggest() = 0;
+    virtual void selectAll() = 0;
+    virtual void setSuggester(Suggester *suggester) = 0;
+    virtual void setInactiveText(const QString &text) = 0;
+    virtual void setText(const QString &text) = 0;
+    virtual AutoComplete *getAutoComplete() = 0;
+    virtual void emitTextChanged(const QString &text) = 0;
+    virtual void returnPressed() = 0;
+    virtual QString text() = 0;
+    virtual QLineEdit *getLineEdit() = 0;
+
+    QWidget *toWidget() {
+        return dynamic_cast<QWidget*>(this);
+    }
+
+signals:
+    void textChanged(const QString &text);
+    void textEdited(const QString &text);
+    void search(const QString &text);
+    void suggestionAccepted(Suggestion *suggestion);
+
+};
+/*
+class SearchWidget : public QWidget, public SearchWidgetInterface {
+
+public:
+    SearchWidget(QWidget *parent = 0);
+    QMenu *menu() const;
+    void setMenu(QMenu *menu);
+    void enableSuggest();
+    void preventSuggest();
+    void selectAll();
+    void setSuggester(Suggester *suggester);
+    void setInactiveText(const QString &text);
+    void setText(const QString &text);
+    AutoComplete *getAutoComplete();
+    void emitTextChanged(const QString &text);
+    void returnPressed();
+    QString text();
+
+private:
+    SearchWidgetInterface *interface;
+
+};
+*/
+
+#endif // SEARCHWIDGET
index ff51fcc330b8e0531494d2ee3c15521bfdad9f0e..e27ff64079b9f1d0222974833f3b3c07d178b68a 100644 (file)
@@ -21,8 +21,9 @@ $END_LICENSE */
 #include "segmentedcontrol.h"
 #include "mainwindow.h"
 #include "painterutils.h"
+#include "fontutils.h"
 
-static const QColor borderColor = QColor(0x26, 0x26, 0x26);
+static const QColor borderColor = QColor(158, 157, 159);
 
 class SegmentedControl::Private {
 public:
@@ -35,6 +36,8 @@ public:
 SegmentedControl::SegmentedControl (QWidget *parent)
     : QWidget(parent), d(new SegmentedControl::Private) {
 
+    setFont(FontUtils::small());
+
     setMouseTracking(true);
 
     d->hoveredAction = 0;
@@ -86,8 +89,8 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
     QPainter p(this);
 
     QLinearGradient linearGrad(rect().topLeft(), rect().bottomLeft());
-    linearGrad.setColorAt(0, borderColor);
-    linearGrad.setColorAt(1, QColor(0x3c, 0x3c, 0x3c));
+    linearGrad.setColorAt(0, QColor(185, 183, 185));
+    linearGrad.setColorAt(1, QColor(176, 176, 178));
     p.fillRect(rect(), QBrush(linearGrad));
 
     // Calculate Buttons Size & Location
@@ -98,7 +101,6 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
     const int actionCount = d->actionList.size();
     for (int i = 0; i < actionCount; i++) {
         QAction *action = d->actionList.at(i);
-
         if (i + 1 == actionCount) {
             rect.setWidth(width - buttonWidth * (actionCount-1));
             drawButton(&p, rect, action);
@@ -106,9 +108,7 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
             drawButton(&p, rect, action);
             rect.moveLeft(rect.x() + rect.width());
         }
-
     }
-
 }
 
 void SegmentedControl::mouseMoveEvent (QMouseEvent *event) {
@@ -195,6 +195,7 @@ void SegmentedControl::drawButton (QPainter *painter,
 void SegmentedControl::drawUnselectedButton (QPainter *painter,
                                         const QRect& rect,
                                         const QAction *action) {
+    painter->setPen(QPen(QColor(0, 0, 0, 128), 1));
     paintButton(painter, rect, action);
 }
 
@@ -210,11 +211,12 @@ void SegmentedControl::drawSelectedButton (QPainter *painter,
     QRadialGradient gradient(hCenter, 0,
                              width,
                              hCenter, 0);
-    gradient.setColorAt(1, Qt::black);
-    gradient.setColorAt(0, QColor(0x33, 0x33, 0x33));
+    gradient.setColorAt(1, QColor(212, 210, 212));
+    gradient.setColorAt(0, QColor(203, 203, 205));
     painter->fillRect(0, 0, width, height, QBrush(gradient));
 
     painter->restore();
+    painter->setPen(QPen(QColor(0, 0, 0, 232), 1));
     paintButton(painter, rect, action);
 }
 
@@ -225,38 +227,23 @@ void SegmentedControl::paintButton(QPainter *painter, const QRect& rect, const Q
     const int height = rect.height();
     const int width = rect.width();
 
-    if (action == d->pressedAction && action != d->checkedAction) {
-        const int hCenter = width * .5;
-        QRadialGradient gradient(hCenter, 0,
-                                 width,
-                                 hCenter, 0);
-        gradient.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
-        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 16));
-        painter->fillRect(0, 0, width, height, QBrush(gradient));
-    } else if (action == d->hoveredAction && action != d->checkedAction) {
-        const int hCenter = width * .5;
-        QRadialGradient gradient(hCenter, 0,
-                                 width,
-                                 hCenter, 0);
-        gradient.setColorAt(1, QColor(0xff, 0xff, 0xff, 0));
-        gradient.setColorAt(0, QColor(0xff, 0xff, 0xff, 16));
-        painter->fillRect(0, 0, width, height, QBrush(gradient));
-    }
-
+    painter->save();
     painter->setPen(borderColor);
 #if defined(APP_MAC) | defined(APP_WIN)
     painter->drawRect(-1, -1, width, height);
 #else
     painter->drawRect(0, 0, width, height - 1);
 #endif
+    painter->restore();
 
     const QString text = action->text();
 
     // text shadow
+    /*
     painter->setPen(QColor(0, 0, 0, 128));
     painter->drawText(0, -1, width, height, Qt::AlignCenter, text);
+    */
 
-    painter->setPen(QPen(Qt::white, 1));
     painter->drawText(0, 0, width, height, Qt::AlignCenter, text);
 
     if (action->property("notifyCount").isValid()) {
@@ -267,5 +254,23 @@ void SegmentedControl::paintButton(QPainter *painter, const QRect& rect, const Q
         PainterUtils::paintBadge(painter, action->property("notifyCount").toString());
     }
 
+    if (action == d->pressedAction && action != d->checkedAction) {
+        const int hCenter = width * .5;
+        QRadialGradient gradient(hCenter, 0,
+                                 width,
+                                 hCenter, 0);
+        gradient.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
+        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 32));
+        painter->fillRect(0, 0, width, height, QBrush(gradient));
+    } else if (action == d->hoveredAction && action != d->checkedAction) {
+        const int hCenter = width * .5;
+        QRadialGradient gradient(hCenter, 0,
+                                 width,
+                                 hCenter, 0);
+        gradient.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
+        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 16));
+        painter->fillRect(0, 0, width, height, QBrush(gradient));
+    }
+
     painter->restore();
 }
diff --git a/src/urllineedit.cpp b/src/urllineedit.cpp
deleted file mode 100644 (file)
index 1b79fd0..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial Usage
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://www.qtsoftware.com/contact.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "urllineedit.h"
-#include "searchlineedit.h"
-
-#include <QEvent>
-
-#include <QApplication>
-#include <QCompleter>
-#include <QFocusEvent>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QPainter>
-#include <QStyle>
-#include <QStyleOptionFrameV2>
-
-#include <QtCore/QDebug>
-
-ExLineEdit::ExLineEdit(QWidget *parent)
-    : QWidget(parent)
-    , m_leftWidget(0)
-    , m_lineEdit(new QLineEdit(this))
-    , m_clearButton(0)
-{
-    setFocusPolicy(m_lineEdit->focusPolicy());
-    setAttribute(Qt::WA_InputMethodEnabled);
-    setSizePolicy(m_lineEdit->sizePolicy());
-    setBackgroundRole(m_lineEdit->backgroundRole());
-    setMouseTracking(true);
-    setAcceptDrops(true);
-    setAttribute(Qt::WA_MacShowFocusRect, true);
-    QPalette p = m_lineEdit->palette();
-    setPalette(p);
-
-    // line edit
-    m_lineEdit->setFrame(false);
-    m_lineEdit->setFocusProxy(this);
-    m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
-    m_lineEdit->setStyleSheet("background:transparent");
-    QPalette clearPalette = m_lineEdit->palette();
-    clearPalette.setBrush(QPalette::Base, QBrush(Qt::transparent));
-    m_lineEdit->setPalette(clearPalette);
-
-    // clearButton
-    m_clearButton = new ClearButton(this);
-    connect(m_clearButton, SIGNAL(clicked()),
-            m_lineEdit, SLOT(clear()));
-    connect(m_lineEdit, SIGNAL(textChanged(const QString&)),
-            m_clearButton, SLOT(textChanged(const QString&)));
-}
-
-void ExLineEdit::setFont(const QFont &font) {
-    m_lineEdit->setFont(font);
-    updateGeometries();
-}
-
-void ExLineEdit::setLeftWidget(QWidget *widget)
-{
-    m_leftWidget = widget;
-}
-
-QWidget *ExLineEdit::leftWidget() const
-{
-    return m_leftWidget;
-}
-
-void ExLineEdit::resizeEvent(QResizeEvent *event)
-{
-    Q_ASSERT(m_leftWidget);
-    updateGeometries();
-    QWidget::resizeEvent(event);
-}
-
-void ExLineEdit::updateGeometries()
-{
-    QStyleOptionFrameV2 panel;
-    initStyleOption(&panel);
-    QRect rect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
-
-    int padding = 3;
-    // int height = rect.height() + padding*2;
-    int width = rect.width();
-
-    // int m_leftWidgetHeight = m_leftWidget->height();
-    m_leftWidget->setGeometry(rect.x() + 2,          0,
-                              m_leftWidget->width(), m_leftWidget->height());
-
-    int clearButtonWidth = this->height();
-    m_lineEdit->setGeometry(m_leftWidget->x() + m_leftWidget->width(),        padding,
-                            width - clearButtonWidth - m_leftWidget->width(), this->height() - padding*2);
-
-    m_clearButton->setGeometry(this->width() - clearButtonWidth, 0,
-                               clearButtonWidth, this->height());
-}
-
-void ExLineEdit::initStyleOption(QStyleOptionFrameV2 *option) const
-{
-    option->initFrom(this);
-    option->rect = contentsRect();
-    option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this);
-    option->midLineWidth = 0;
-    option->state |= QStyle::State_Sunken;
-    if (m_lineEdit->isReadOnly())
-        option->state |= QStyle::State_ReadOnly;
-#ifdef QT_KEYPAD_NAVIGATION
-    if (hasEditFocus())
-        option->state |= QStyle::State_HasEditFocus;
-#endif
-    option->features = QStyleOptionFrameV2::None;
-}
-
-QSize ExLineEdit::sizeHint() const
-{
-    m_lineEdit->setFrame(true);
-    QSize size = m_lineEdit->sizeHint();
-    m_lineEdit->setFrame(false);
-    size = size + QSize(3, 3);
-    return size;
-}
-
-void ExLineEdit::focusInEvent(QFocusEvent *event)
-{
-    m_lineEdit->event(event);
-    QWidget::focusInEvent(event);
-}
-
-void ExLineEdit::focusOutEvent(QFocusEvent *event)
-{
-    m_lineEdit->event(event);
-
-    if (m_lineEdit->completer()) {
-        connect(m_lineEdit->completer(), SIGNAL(activated(QString)),
-                         m_lineEdit, SLOT(setText(QString)));
-        connect(m_lineEdit->completer(), SIGNAL(highlighted(QString)),
-                         m_lineEdit, SLOT(_q_completionHighlighted(QString)));
-    }
-    QWidget::focusOutEvent(event);
-}
-
-void ExLineEdit::keyPressEvent(QKeyEvent *event)
-{
-    if (event->key() == Qt::Key_Escape && !m_lineEdit->text().isEmpty()) {
-        m_lineEdit->clear();
-    }
-    m_lineEdit->event(event);
-    QWidget::keyPressEvent(event);
-}
-
-bool ExLineEdit::event(QEvent *event)
-{
-    if (event->type() == QEvent::ShortcutOverride ||
-        event->type() == QEvent::InputMethod)
-        m_lineEdit->event(event);
-    return QWidget::event(event);
-}
-
-void ExLineEdit::paintEvent(QPaintEvent *)
-{
-    QPainter p(this);
-    QStyleOptionFrameV2 panel;
-    initStyleOption(&panel);
-    style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
-}
diff --git a/src/urllineedit.h b/src/urllineedit.h
deleted file mode 100644 (file)
index 3cda04c..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* $BEGIN_LICENSE
-
-This file is part of Minitube.
-Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
-
-Minitube is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Minitube is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
-
-$END_LICENSE */
-
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial Usage
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://www.qtsoftware.com/contact.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef URLLINEEDIT_H
-#define URLLINEEDIT_H
-
-#include <QUrl>
-#include <QWidget>
-#include <QLineEdit>
-#include <QStyleOptionFrame>
-
-QT_BEGIN_NAMESPACE
-class QLineEdit;
-QT_END_NAMESPACE
-
-class ClearButton;
-class ExLineEdit : public QWidget
-{
-    Q_OBJECT
-
-public:
-    ExLineEdit(QWidget *parent = 0);
-
-    inline QLineEdit *lineEdit() const { return m_lineEdit; }
-
-    void setLeftWidget(QWidget *widget);
-    QWidget *leftWidget() const;
-    void clear() {
-        m_lineEdit->clear();
-    }
-    QString text() {
-        return m_lineEdit->text();
-    }
-    QSize sizeHint() const;
-    void updateGeometries();
-    void setFont(const QFont &);
-
-protected:
-    void focusInEvent(QFocusEvent *event);
-    void focusOutEvent(QFocusEvent *event);
-    void keyPressEvent(QKeyEvent *event);
-    void paintEvent(QPaintEvent *event);
-    void resizeEvent(QResizeEvent *event);
-    bool event(QEvent *event);
-    void initStyleOption(QStyleOptionFrameV2 *option) const;
-
-    QWidget *m_leftWidget;
-    QLineEdit *m_lineEdit;
-    ClearButton *m_clearButton;
-};
-
-#endif // URLLINEEDIT_H
-