1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Global shortcuts to load pages in Speed Dial (Ctrl + Number)

- Ctrl + 1,2,3 ... 9 will load dials on the number position
- Alt + 1,2,3 ... 8 will switch to tab on the number position
   * Alt + 9 will switch to last tab
This commit is contained in:
nowrep 2012-02-05 17:13:08 +01:00
parent 7167ce4a03
commit 30df150fe0
3 changed files with 63 additions and 33 deletions

View File

@ -62,6 +62,7 @@
#include "enhancedmenu.h" #include "enhancedmenu.h"
#include "settings.h" #include "settings.h"
#include "webtab.h" #include "webtab.h"
#include "speeddial.h"
const QString QupZilla::VERSION = "1.1.5"; const QString QupZilla::VERSION = "1.1.5";
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__; const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
@ -1542,6 +1543,8 @@ void QupZilla::resizeEvent(QResizeEvent* event)
void QupZilla::keyPressEvent(QKeyEvent* event) void QupZilla::keyPressEvent(QKeyEvent* event)
{ {
int number = -1;
switch (event->key()) { switch (event->key()) {
case Qt::Key_Back: case Qt::Key_Back:
weView()->back(); weView()->back();
@ -1616,33 +1619,54 @@ void QupZilla::keyPressEvent(QKeyEvent* event)
} }
break; break;
case Qt::Key_0:
case Qt::Key_1: case Qt::Key_1:
number = 1;
break;
case Qt::Key_2: case Qt::Key_2:
number = 2;
break;
case Qt::Key_3: case Qt::Key_3:
number = 3;
break;
case Qt::Key_4: case Qt::Key_4:
number = 4;
break;
case Qt::Key_5: case Qt::Key_5:
number = 5;
break;
case Qt::Key_6: case Qt::Key_6:
number = 6;
break;
case Qt::Key_7: case Qt::Key_7:
number = 7;
break;
case Qt::Key_8: case Qt::Key_8:
qDebug() << event->modifiers(); number = 8;
if (event->modifiers() & Qt::AltModifier) { break;
m_tabWidget->setCurrentIndex(event->text().toInt() - 1); case Qt::Key_9:
event->accept(); number = 9;
}
break; break;
case Qt::Key_9: default:
if (event->modifiers() & Qt::AltModifier) { break;
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
event->accept();
} }
default: if (number != -1) {
if (event->modifiers() & Qt::AltModifier) {
if (number == 9) {
number = m_tabWidget->count();
}
m_tabWidget->setCurrentIndex(number - 1);
return; return;
} }
if (event->modifiers() & Qt::ControlModifier) {
qDebug("event"); const QUrl &url = mApp->plugins()->speedDial()->urlForShortcut(number - 1);
if (url.isValid()) {
loadAddress(url);
return;
}
}
}
QMainWindow::keyPressEvent(event); QMainWindow::keyPressEvent(event);
} }

View File

@ -20,6 +20,8 @@
#include "pagethumbnailer.h" #include "pagethumbnailer.h"
#include "settings.h" #include "settings.h"
#define ENSURE_LOADED if (!m_loaded) loadSettings();
SpeedDial::SpeedDial(QObject* parent) SpeedDial::SpeedDial(QObject* parent)
: QObject(parent) : QObject(parent)
, m_maxPagesInRow(4) , m_maxPagesInRow(4)
@ -61,6 +63,8 @@ void SpeedDial::loadSettings()
void SpeedDial::saveSettings() void SpeedDial::saveSettings()
{ {
ENSURE_LOADED;
if (m_webPages.isEmpty()) { if (m_webPages.isEmpty()) {
return; return;
} }
@ -77,6 +81,8 @@ void SpeedDial::saveSettings()
SpeedDial::Page SpeedDial::pageForUrl(const QUrl &url) SpeedDial::Page SpeedDial::pageForUrl(const QUrl &url)
{ {
ENSURE_LOADED;
const QString &urlString = url.toString(); const QString &urlString = url.toString();
foreach(const Page & page, m_webPages) { foreach(const Page & page, m_webPages) {
@ -90,6 +96,8 @@ SpeedDial::Page SpeedDial::pageForUrl(const QUrl &url)
QUrl SpeedDial::urlForShortcut(int key) QUrl SpeedDial::urlForShortcut(int key)
{ {
ENSURE_LOADED;
if (key < 0 || m_webPages.count() <= key) { if (key < 0 || m_webPages.count() <= key) {
return QUrl(); return QUrl();
} }
@ -106,6 +114,8 @@ void SpeedDial::addWebFrame(QWebFrame* frame)
void SpeedDial::addPage(const QUrl &url, const QString &title) void SpeedDial::addPage(const QUrl &url, const QString &title)
{ {
ENSURE_LOADED;
if (url.isEmpty()) { if (url.isEmpty()) {
return; return;
} }
@ -126,6 +136,8 @@ void SpeedDial::addPage(const QUrl &url, const QString &title)
void SpeedDial::removePage(const Page &page) void SpeedDial::removePage(const Page &page)
{ {
ENSURE_LOADED;
if (page.url.isEmpty()) { if (page.url.isEmpty()) {
return; return;
} }
@ -143,45 +155,35 @@ void SpeedDial::removePage(const Page &page)
int SpeedDial::pagesInRow() int SpeedDial::pagesInRow()
{ {
if (!m_loaded) { ENSURE_LOADED;
loadSettings();
}
return m_maxPagesInRow; return m_maxPagesInRow;
} }
int SpeedDial::sdSize() int SpeedDial::sdSize()
{ {
if (!m_loaded) { ENSURE_LOADED;
loadSettings();
}
return m_sizeOfSpeedDials; return m_sizeOfSpeedDials;
} }
QString SpeedDial::backgroundImage() QString SpeedDial::backgroundImage()
{ {
if (!m_loaded) { ENSURE_LOADED;
loadSettings();
}
return m_backgroundImage; return m_backgroundImage;
} }
QString SpeedDial::backgroundImageSize() QString SpeedDial::backgroundImageSize()
{ {
if (!m_loaded) { ENSURE_LOADED;
loadSettings();
}
return m_backgroundImageSize; return m_backgroundImageSize;
} }
QString SpeedDial::initialScript() QString SpeedDial::initialScript()
{ {
if (!m_loaded) { ENSURE_LOADED;
loadSettings();
}
if (!m_regenerateScript) { if (!m_regenerateScript) {
return m_initialScript; return m_initialScript;

View File

@ -575,25 +575,29 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg)
void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg) void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
{ {
Q_UNUSED(originatingFrame)
if (m_blockAlerts || m_runningLoop) { if (m_blockAlerts || m_runningLoop) {
return; return;
} }
#ifndef NONBLOCK_JS_DIALOGS #ifndef NONBLOCK_JS_DIALOGS
QDialog dialog(view()); QDialog* dialog = new QDialog(view());
Ui_CloseDialog* ui = new Ui_CloseDialog(); Ui_CloseDialog* ui = new Ui_CloseDialog();
ui->setupUi(&dialog); ui->setupUi(dialog);
ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok);
ui->dontAskAgain->setText(tr("Prevent this page from creating additional dialogs")); ui->dontAskAgain->setText(tr("Prevent this page from creating additional dialogs"));
ui->textLabel->setText(Qt::escape(msg)); ui->textLabel->setText(Qt::escape(msg));
ui->iconLabel->setPixmap(mApp->style()->standardPixmap(QStyle::SP_MessageBoxInformation)); ui->iconLabel->setPixmap(mApp->style()->standardPixmap(QStyle::SP_MessageBoxInformation));
ui->buttonBox->setFocus(); ui->buttonBox->setFocus();
dialog.setWindowTitle(tr("JavaScript alert - %1").arg(originatingFrame->url().host())); dialog->setWindowTitle(tr("JavaScript alert - %1").arg(url().host()));
dialog.exec(); dialog->exec();
if (ui->dontAskAgain->isChecked()) { if (ui->dontAskAgain->isChecked()) {
m_blockAlerts = true; m_blockAlerts = true;
} }
delete dialog;
#else #else
WebView* webView = qobject_cast<WebView*>(originatingFrame->page()->view()); WebView* webView = qobject_cast<WebView*>(originatingFrame->page()->view());
ResizableFrame* widget = new ResizableFrame(webView->overlayForJsAlert()); ResizableFrame* widget = new ResizableFrame(webView->overlayForJsAlert());