1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-13 10:32:11 +01:00
* CheckBoxDialog: Rewritten to inherit from QMessageBox

-  QMessageBox supports showing checkbox for Qt >= 5.2

* Add option to disable warning message when closing tabs from tabbar context menu.

- Closes #2178
This commit is contained in:
srazi 2017-04-05 12:57:03 +04:30 committed by David Rosca
parent f961958989
commit 2654081912
8 changed files with 59 additions and 176 deletions

View File

@ -1321,13 +1321,13 @@ void BrowserWindow::closeEvent(QCloseEvent* event)
} }
if (askOnClose && m_tabWidget->normalTabsCount() > 1) { if (askOnClose && m_tabWidget->normalTabsCount() > 1) {
CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, this); CheckBoxDialog dialog(QMessageBox::Yes | QMessageBox::No, this);
dialog.setText(tr("There are still %n open tabs and your session won't be stored. \nAre you sure you want to close this window?", "", m_tabWidget->count())); dialog.setText(tr("There are still %n open tabs and your session won't be stored. \nAre you sure you want to close this window?", "", m_tabWidget->count()));
dialog.setCheckBoxText(tr("Don't ask again")); dialog.setCheckBoxText(tr("Don't ask again"));
dialog.setWindowTitle(tr("There are still open tabs")); dialog.setWindowTitle(tr("There are still open tabs"));
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning)); dialog.setIcon(QMessageBox::Warning);
if (dialog.exec() != QDialog::Accepted) { if (dialog.exec() != QMessageBox::Yes) {
event->ignore(); event->ignore();
return; return;
} }

View File

@ -1097,14 +1097,14 @@ void MainApplication::checkDefaultWebBrowser()
bool checkAgain = true; bool checkAgain = true;
if (!associationManager()->isDefaultForAllCapabilities()) { if (!associationManager()->isDefaultForAllCapabilities()) {
CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, getWindow()); CheckBoxDialog dialog(QMessageBox::Yes | QMessageBox::No, getWindow());
dialog.setText(tr("QupZilla is not currently your default browser. Would you like to make it your default browser?")); dialog.setText(tr("QupZilla is not currently your default browser. Would you like to make it your default browser?"));
dialog.setCheckBoxText(tr("Always perform this check when starting QupZilla.")); dialog.setCheckBoxText(tr("Always perform this check when starting QupZilla."));
dialog.setDefaultCheckState(Qt::Checked); dialog.setDefaultCheckState(Qt::Checked);
dialog.setWindowTitle(tr("Default Browser")); dialog.setWindowTitle(tr("Default Browser"));
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning)); dialog.setIcon(QMessageBox::Warning);
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QMessageBox::Yes) {
associationManager()->registerAllAssociation(); associationManager()->registerAllAssociation();
} }

View File

@ -424,7 +424,6 @@ FORMS += \
other/aboutdialog.ui \ other/aboutdialog.ui \
other/browsinglibrary.ui \ other/browsinglibrary.ui \
other/clearprivatedata.ui \ other/clearprivatedata.ui \
other/checkboxdialog.ui \
other/iconchooser.ui \ other/iconchooser.ui \
other/siteinfo.ui \ other/siteinfo.ui \
other/siteinfowidget.ui \ other/siteinfowidget.ui \

View File

@ -1,6 +1,7 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2017 Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,47 +17,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "checkboxdialog.h" #include "checkboxdialog.h"
#include "ui_checkboxdialog.h" #include <QCheckBox>
CheckBoxDialog::CheckBoxDialog(const QDialogButtonBox::StandardButtons &buttons, QWidget* parent) CheckBoxDialog::CheckBoxDialog(const QMessageBox::StandardButtons &buttons, QWidget* parent)
: QDialog(parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) : QMessageBox(parent)
, ui(new Ui::CheckBoxDialog) , m_checkBox(new QCheckBox)
{ {
ui->setupUi(this); setCheckBox(m_checkBox);
setStandardButtons(buttons);
ui->buttonBox->setStandardButtons(buttons); setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
}
void CheckBoxDialog::setIcon(const QIcon &icon)
{
ui->iconLabel->setPixmap(icon.pixmap(48, 48));
ui->iconLabel->setFixedWidth(48);
}
void CheckBoxDialog::setText(const QString &text)
{
ui->textLabel->setText(text);
} }
void CheckBoxDialog::setCheckBoxText(const QString &text) void CheckBoxDialog::setCheckBoxText(const QString &text)
{ {
ui->checkBox->setText(text); m_checkBox->setText(text);
} }
bool CheckBoxDialog::isChecked() const bool CheckBoxDialog::isChecked() const
{ {
return ui->checkBox->isChecked(); return m_checkBox->isChecked();
} }
void CheckBoxDialog::setDefaultCheckState(Qt::CheckState state) void CheckBoxDialog::setDefaultCheckState(Qt::CheckState state)
{ {
ui->checkBox->setChecked(state == Qt::Checked); m_checkBox->setChecked(state == Qt::Checked);
}
int CheckBoxDialog::exec()
{
ui->buttonBox->setFocus();
setMaximumSize(size());
return QDialog::exec();
} }

View File

@ -1,6 +1,7 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2017 Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,35 +19,23 @@
#ifndef CHECKBOXDIALOG_H #ifndef CHECKBOXDIALOG_H
#define CHECKBOXDIALOG_H #define CHECKBOXDIALOG_H
#include <QDialog> #include <QMessageBox>
#include <QDialogButtonBox>
#include "qzcommon.h" #include "qzcommon.h"
namespace Ui class QUPZILLA_EXPORT CheckBoxDialog : public QMessageBox
{
class CheckBoxDialog;
}
class QUPZILLA_EXPORT CheckBoxDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CheckBoxDialog(const QDialogButtonBox::StandardButtons &buttons, QWidget* parent = 0); explicit CheckBoxDialog(const QMessageBox::StandardButtons &buttons, QWidget* parent = 0);
void setIcon(const QIcon &icon);
void setText(const QString &text);
void setCheckBoxText(const QString &text); void setCheckBoxText(const QString &text);
bool isChecked() const; bool isChecked() const;
void setDefaultCheckState(Qt::CheckState state); void setDefaultCheckState(Qt::CheckState state);
public slots:
int exec();
private: private:
Ui::CheckBoxDialog* ui; QCheckBox* m_checkBox;
}; };

View File

@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CheckBoxDialog</class>
<widget class="QDialog" name="CheckBoxDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>409</width>
<height>94</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="iconLabel">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CheckBoxDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CheckBoxDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -25,11 +25,11 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "pluginproxy.h" #include "pluginproxy.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "checkboxdialog.h"
#include <QMenu> #include <QMenu>
#include <QMimeData> #include <QMimeData>
#include <QMouseEvent> #include <QMouseEvent>
#include <QMessageBox>
#include <QStyleOption> #include <QStyleOption>
#include <QApplication> #include <QApplication>
#include <QTimer> #include <QTimer>
@ -127,33 +127,48 @@ void TabBar::overflowChanged(bool overflowed)
} }
} }
//TODO: replace these 3 w/ preferencable mbox static bool canCloseTabs(const QString &settingsKey, const QString &title, const QString &description)
{
Settings settings;
bool ask = settings.value("Browser-Tabs-Settings/" + settingsKey, true).toBool();
if (ask) {
CheckBoxDialog dialog(QMessageBox::Yes | QMessageBox::No, mApp->activeWindow());
dialog.setDefaultButton(QMessageBox::No);
dialog.setWindowTitle(title);
dialog.setText(description);
dialog.setCheckBoxText(TabBar::tr("Don't ask again"));
dialog.setIcon(QMessageBox::Question);
if (dialog.exec() != QMessageBox::Yes) {
return false;
}
if (dialog.isChecked()) {
settings.setValue("Browser-Tabs-Settings/" + settingsKey, false);
}
}
return true;
}
void TabBar::closeAllButCurrent() void TabBar::closeAllButCurrent()
{ {
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close other tabs?"), if (canCloseTabs(QLatin1String("AskOnClosingAllButCurrent"), tr("Close Tabs"), tr("Do you really want to close other tabs?"))) {
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::Yes) {
emit closeAllButCurrent(m_clickedTab); emit closeAllButCurrent(m_clickedTab);
} }
} }
void TabBar::closeToRight() void TabBar::closeToRight()
{ {
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close all tabs to the right?"), if (canCloseTabs(QLatin1String("AskOnClosingToRight"), tr("Close Tabs"), tr("Do you really want to close all tabs to the right?"))) {
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::Yes) {
emit closeToRight(m_clickedTab); emit closeToRight(m_clickedTab);
} }
} }
void TabBar::closeToLeft() void TabBar::closeToLeft()
{ {
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close all tabs to the left?"), if (canCloseTabs(QLatin1String("AskOnClosingToLeft"), tr("Close Tabs"), tr("Do you really want to close all tabs to the left?"))) {
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::Yes) {
emit closeToLeft(m_clickedTab); emit closeToLeft(m_clickedTab);
} }
} }

View File

@ -272,7 +272,7 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
return; return;
} }
CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, view()); CheckBoxDialog dialog(QMessageBox::Yes | QMessageBox::No, view());
const QString wrappedUrl = QzTools::alignTextToWidth(url.toString(), "<br/>", dialog.fontMetrics(), 450); const QString wrappedUrl = QzTools::alignTextToWidth(url.toString(), "<br/>", dialog.fontMetrics(), 450);
const QString text = tr("QupZilla cannot handle <b>%1:</b> links. The requested link " const QString text = tr("QupZilla cannot handle <b>%1:</b> links. The requested link "
@ -282,10 +282,10 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
dialog.setText(text); dialog.setText(text);
dialog.setCheckBoxText(tr("Remember my choice for this protocol")); dialog.setCheckBoxText(tr("Remember my choice for this protocol"));
dialog.setWindowTitle(tr("External Protocol Request")); dialog.setWindowTitle(tr("External Protocol Request"));
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxQuestion)); dialog.setIcon(QMessageBox::Question);
switch (dialog.exec()) { switch (dialog.exec()) {
case QDialog::Accepted: case QMessageBox::Yes:
if (dialog.isChecked()) { if (dialog.isChecked()) {
qzSettings->autoOpenProtocols.append(protocol); qzSettings->autoOpenProtocols.append(protocol);
qzSettings->saveSettings(); qzSettings->saveSettings();
@ -295,7 +295,7 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
break; break;
case QDialog::Rejected: case QMessageBox::No:
if (dialog.isChecked()) { if (dialog.isChecked()) {
qzSettings->blockedProtocols.append(protocol); qzSettings->blockedProtocols.append(protocol);
qzSettings->saveSettings(); qzSettings->saveSettings();
@ -546,11 +546,11 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg)
title.append(QString(" - %1").arg(url().host())); title.append(QString(" - %1").arg(url().host()));
} }
CheckBoxDialog dialog(QDialogButtonBox::Ok, view()); CheckBoxDialog dialog(QMessageBox::Ok, view());
dialog.setWindowTitle(title); dialog.setWindowTitle(title);
dialog.setText(msg); dialog.setText(msg);
dialog.setCheckBoxText(tr("Prevent this page from creating additional dialogs")); dialog.setCheckBoxText(tr("Prevent this page from creating additional dialogs"));
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxInformation)); dialog.setIcon(QMessageBox::Information);
dialog.exec(); dialog.exec();
m_blockAlerts = dialog.isChecked(); m_blockAlerts = dialog.isChecked();