summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Tröscher <fritz_van_tom@hotmail.com>2011-09-11 19:09:41 +0200
committerJohannes Tröscher <fritz_van_tom@hotmail.com>2011-09-11 19:09:41 +0200
commit884b8a5c12e5d5d61a9fb7d1eece11b45c2f1192 (patch)
tree7062e0700e7f07ace9278f2407953166604806f7
parentfix layout of favouriteWidget (diff)
downloadrekonq-884b8a5c12e5d5d61a9fb7d1eece11b45c2f1192.tar.xz
fix layout of webshortcutWidget + code cleanup
REVIEWED-BY: trustMe
-rw-r--r--src/urlbar/webshortcutwidget.cpp125
-rw-r--r--src/urlbar/webshortcutwidget.h12
2 files changed, 51 insertions, 86 deletions
diff --git a/src/urlbar/webshortcutwidget.cpp b/src/urlbar/webshortcutwidget.cpp
index 495e0d2e..111ff836 100644
--- a/src/urlbar/webshortcutwidget.cpp
+++ b/src/urlbar/webshortcutwidget.cpp
@@ -19,92 +19,70 @@
* Boston, MA 02110-1301, USA.
*/
+// Self Includes
#include "webshortcutwidget.h"
#include "rekonq_defines.h"
-#include <QtCore/QTimer>
-#include <QtCore/QSet>
-#include <QtGui/QBoxLayout>
-#include <QtGui/QLabel>
-#include <QtGui/QLineEdit>
-#include <QtGui/QPushButton>
-#include <QtGui/QFormLayout>
-
-
+// KDE Includes
#include <KGlobalSettings>
#include <KIcon>
#include <KLocale>
#include <KServiceTypeTrader>
+// Qt Includes
+#include <QSet>
+#include <QLabel>
+#include <QLineEdit>
+#include <QDialogButtonBox>
+#include <QFormLayout>
+
WebShortcutWidget::WebShortcutWidget(QWidget *parent)
- : QDialog(parent)
+ : QMenu(parent)
+ , m_nameLineEdit(new QLineEdit(this))
+ , m_wsLineEdit(new QLineEdit(this))
+ , m_noteLabel(new QLabel(this))
{
- QVBoxLayout *mainLayout = new QVBoxLayout();
- QHBoxLayout *titleLayout = new QHBoxLayout();
- mainLayout->addLayout(titleLayout);
- QLabel *iconLabel = new QLabel(this);
+ setAttribute(Qt::WA_DeleteOnClose);
+ setFixedWidth(350);
- KIcon wsIcon("edit-web-search");
- if (wsIcon.isNull())
- {
- wsIcon = KIcon("preferences-web-browser-shortcuts");
- }
+ QFormLayout *layout = new QFormLayout(this);
+ QVBoxLayout *vLay = new QVBoxLayout(this);
- iconLabel->setPixmap(wsIcon.pixmap(22, 22));
- titleLayout->addWidget(iconLabel);
- m_searchTitleLabel = new QLabel(i18n("Add Search Engine"), this);
- QFont boldFont = KGlobalSettings::generalFont();
- boldFont.setBold(true);
- m_searchTitleLabel->setFont(boldFont);
- titleLayout->addWidget(m_searchTitleLabel);
- titleLayout->addStretch();
-
- QFormLayout *formLayout = new QFormLayout();
- mainLayout->addLayout(formLayout);
-
- QFont smallFont = KGlobalSettings::smallestReadableFont();
- m_nameLineEdit = new QLineEdit(this);
- m_nameLineEdit->setEnabled(false);
- m_nameLineEdit->setFont(smallFont);
- QLabel *nameLabel = new QLabel(i18n("Name:"), this);
- nameLabel->setFont(smallFont);
- formLayout->addRow(nameLabel, m_nameLineEdit);
+ // Web Search Icon
+ QLabel *webSearchIcon = new QLabel(this);
+ webSearchIcon->setPixmap(KIcon("edit-web-search").pixmap(32, 32));
- QLabel *shortcutsLabel = new QLabel(i18n("Shortcuts:"), this);
- shortcutsLabel->setFont(smallFont);
- m_wsLineEdit = new QLineEdit(this);
- m_wsLineEdit->setMinimumWidth(100);
- m_wsLineEdit->setFont(smallFont);
- formLayout->addRow(shortcutsLabel, m_wsLineEdit);
- connect(m_wsLineEdit, SIGNAL(textChanged(QString)), SLOT(shortcutsChanged(const QString&)));
+ // Title
+ QLabel *titleLabel = new QLabel(this);
+ titleLabel->setText("<h4>" + i18n("Add Search Engine") + "</h4>");
+ vLay->addWidget(titleLabel);
- m_noteLabel = new QLabel(this);
- m_noteLabel->setFont(boldFont);
- m_noteLabel->setWordWrap(true);
- formLayout->addRow(m_noteLabel);
- m_noteLabel->setVisible(false);
+ // Name
+ vLay->addWidget(m_nameLineEdit);
- mainLayout->addStretch();
+ layout->addRow(webSearchIcon, vLay);
- QHBoxLayout *buttonLayout = new QHBoxLayout();
- mainLayout->addLayout(buttonLayout);
- buttonLayout->addStretch();
- m_okButton = new QPushButton(i18n("Ok"), this);
- m_okButton->setDefault(true);
- buttonLayout->addWidget(m_okButton);
- connect(m_okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
+ // Shortcuts
+ QLabel *shortcutsLabel = new QLabel(i18n("Shortcuts:"), this);
+ layout->addRow(shortcutsLabel, m_wsLineEdit);
+ connect(m_wsLineEdit, SIGNAL(textChanged(QString)), SLOT(shortcutsChanged(const QString&)));
- QPushButton *cancelButton = new QPushButton(i18n("Cancel"), this);
- buttonLayout->addWidget(cancelButton);
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
+ // Note
+ m_noteLabel->setWordWrap(true);
+ layout->addRow(m_noteLabel);
+ m_noteLabel->hide();
- setLayout(mainLayout);
+ // Ok & Cancel buttons
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+ layout->addWidget(buttonBox);
- setMinimumWidth(250);
+ setLayout(layout);
m_providers = KServiceTypeTrader::self()->query("SearchProvider");
- QTimer::singleShot(0, m_wsLineEdit, SLOT(setFocus()));
+ m_wsLineEdit->setFocus();
}
@@ -112,12 +90,9 @@ void WebShortcutWidget::showAt(const QPoint &pos)
{
adjustSize();
- QPoint p;
- p.setX(pos.x() - width());
- p.setY(pos.y() + 10);
-
+ QPoint p(pos.x() - width(), pos.y() + 10);
move(p);
- QDialog::show();
+ exec();
}
@@ -130,16 +105,10 @@ void WebShortcutWidget::show(const KUrl &url, const QString &openSearchName, con
}
-void WebShortcutWidget::okClicked()
+void WebShortcutWidget::accept()
{
- hide();
emit webShortcutSet(m_url, m_nameLineEdit->text(), m_wsLineEdit->text());
-}
-
-
-void WebShortcutWidget::cancelClicked()
-{
- hide();
+ close();
}
@@ -169,14 +138,12 @@ void WebShortcutWidget::shortcutsChanged(const QString& newShorthands)
if (!contenderName.isEmpty())
{
- m_okButton->setEnabled(false);
m_noteLabel->setText(i18n("The shortcut \"%1\" is already assigned to \"%2\".", contenderWS, contenderName));
m_noteLabel->setVisible(true);
resize(minimumSize().width(), minimumSizeHint().height() + 15);
}
else
{
- m_okButton->setEnabled(true);
m_noteLabel->clear();
bool noteIsVisible = m_noteLabel->isVisible();
m_noteLabel->setVisible(false);
diff --git a/src/urlbar/webshortcutwidget.h b/src/urlbar/webshortcutwidget.h
index 2cf1eedf..2a5ede34 100644
--- a/src/urlbar/webshortcutwidget.h
+++ b/src/urlbar/webshortcutwidget.h
@@ -22,35 +22,33 @@
#ifndef WEBSHORTCUTWIDGET_H
#define WEBSHORTCUTWIDGET_H
-#include <QtGui/QDialog>
+#include <QMenu>
#include <KUrl>
#include <KService>
class QLabel;
class QLineEdit;
+class QPushButton;
-class WebShortcutWidget : public QDialog
+class WebShortcutWidget : public QMenu
{
Q_OBJECT
public:
- explicit WebShortcutWidget(QWidget *parent = 0);
+ WebShortcutWidget(QWidget *parent = 0);
void show(const KUrl &url, const QString &openSearchName, const QPoint &pos);
private slots:
- void okClicked();
- void cancelClicked();
+ void accept();
void shortcutsChanged(const QString& newShorthands);
signals:
void webShortcutSet(const KUrl &url, const QString &openSearchName, const QString &webShortcut);
private:
- QLabel *m_searchTitleLabel;
QLineEdit *m_wsLineEdit;
QLineEdit *m_nameLineEdit;
QLabel *m_noteLabel;
- QPushButton *m_okButton;
KService::List m_providers;
KUrl m_url;