mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Fix 2178 (#2292)
* 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:
parent
f961958989
commit
2654081912
|
@ -1321,13 +1321,13 @@ void BrowserWindow::closeEvent(QCloseEvent* event)
|
|||
}
|
||||
|
||||
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.setCheckBoxText(tr("Don't ask again"));
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1097,14 +1097,14 @@ void MainApplication::checkDefaultWebBrowser()
|
|||
bool checkAgain = true;
|
||||
|
||||
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.setCheckBoxText(tr("Always perform this check when starting QupZilla."));
|
||||
dialog.setDefaultCheckState(Qt::Checked);
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -424,7 +424,6 @@ FORMS += \
|
|||
other/aboutdialog.ui \
|
||||
other/browsinglibrary.ui \
|
||||
other/clearprivatedata.ui \
|
||||
other/checkboxdialog.ui \
|
||||
other/iconchooser.ui \
|
||||
other/siteinfo.ui \
|
||||
other/siteinfowidget.ui \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* ============================================================
|
||||
* 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
|
||||
* 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/>.
|
||||
* ============================================================ */
|
||||
#include "checkboxdialog.h"
|
||||
#include "ui_checkboxdialog.h"
|
||||
#include <QCheckBox>
|
||||
|
||||
CheckBoxDialog::CheckBoxDialog(const QDialogButtonBox::StandardButtons &buttons, QWidget* parent)
|
||||
: QDialog(parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
||||
, ui(new Ui::CheckBoxDialog)
|
||||
CheckBoxDialog::CheckBoxDialog(const QMessageBox::StandardButtons &buttons, QWidget* parent)
|
||||
: QMessageBox(parent)
|
||||
, m_checkBox(new QCheckBox)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->buttonBox->setStandardButtons(buttons);
|
||||
}
|
||||
|
||||
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);
|
||||
setCheckBox(m_checkBox);
|
||||
setStandardButtons(buttons);
|
||||
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
|
||||
}
|
||||
|
||||
void CheckBoxDialog::setCheckBoxText(const QString &text)
|
||||
{
|
||||
ui->checkBox->setText(text);
|
||||
m_checkBox->setText(text);
|
||||
}
|
||||
|
||||
bool CheckBoxDialog::isChecked() const
|
||||
{
|
||||
return ui->checkBox->isChecked();
|
||||
return m_checkBox->isChecked();
|
||||
}
|
||||
|
||||
void CheckBoxDialog::setDefaultCheckState(Qt::CheckState state)
|
||||
{
|
||||
ui->checkBox->setChecked(state == Qt::Checked);
|
||||
}
|
||||
|
||||
int CheckBoxDialog::exec()
|
||||
{
|
||||
ui->buttonBox->setFocus();
|
||||
setMaximumSize(size());
|
||||
|
||||
return QDialog::exec();
|
||||
m_checkBox->setChecked(state == Qt::Checked);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* ============================================================
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,35 +19,23 @@
|
|||
#ifndef CHECKBOXDIALOG_H
|
||||
#define CHECKBOXDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CheckBoxDialog;
|
||||
}
|
||||
|
||||
class QUPZILLA_EXPORT CheckBoxDialog : public QDialog
|
||||
class QUPZILLA_EXPORT CheckBoxDialog : public QMessageBox
|
||||
{
|
||||
Q_OBJECT
|
||||
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);
|
||||
|
||||
bool isChecked() const;
|
||||
void setDefaultCheckState(Qt::CheckState state);
|
||||
|
||||
public slots:
|
||||
int exec();
|
||||
|
||||
private:
|
||||
Ui::CheckBoxDialog* ui;
|
||||
QCheckBox* m_checkBox;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -25,11 +25,11 @@
|
|||
#include "mainapplication.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "iconprovider.h"
|
||||
#include "checkboxdialog.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QStyleOption>
|
||||
#include <QApplication>
|
||||
#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()
|
||||
{
|
||||
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close other tabs?"),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||
|
||||
if (button == QMessageBox::Yes) {
|
||||
if (canCloseTabs(QLatin1String("AskOnClosingAllButCurrent"), tr("Close Tabs"), tr("Do you really want to close other tabs?"))) {
|
||||
emit closeAllButCurrent(m_clickedTab);
|
||||
}
|
||||
}
|
||||
|
||||
void TabBar::closeToRight()
|
||||
{
|
||||
QMessageBox::StandardButton button = QMessageBox::question(this, 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) {
|
||||
if (canCloseTabs(QLatin1String("AskOnClosingToRight"), tr("Close Tabs"), tr("Do you really want to close all tabs to the right?"))) {
|
||||
emit closeToRight(m_clickedTab);
|
||||
}
|
||||
}
|
||||
|
||||
void TabBar::closeToLeft()
|
||||
{
|
||||
QMessageBox::StandardButton button = QMessageBox::question(this, 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) {
|
||||
if (canCloseTabs(QLatin1String("AskOnClosingToLeft"), tr("Close Tabs"), tr("Do you really want to close all tabs to the left?"))) {
|
||||
emit closeToLeft(m_clickedTab);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
|
|||
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 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.setCheckBoxText(tr("Remember my choice for this protocol"));
|
||||
dialog.setWindowTitle(tr("External Protocol Request"));
|
||||
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxQuestion));
|
||||
dialog.setIcon(QMessageBox::Question);
|
||||
|
||||
switch (dialog.exec()) {
|
||||
case QDialog::Accepted:
|
||||
case QMessageBox::Yes:
|
||||
if (dialog.isChecked()) {
|
||||
qzSettings->autoOpenProtocols.append(protocol);
|
||||
qzSettings->saveSettings();
|
||||
|
@ -295,7 +295,7 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
|
|||
QDesktopServices::openUrl(url);
|
||||
break;
|
||||
|
||||
case QDialog::Rejected:
|
||||
case QMessageBox::No:
|
||||
if (dialog.isChecked()) {
|
||||
qzSettings->blockedProtocols.append(protocol);
|
||||
qzSettings->saveSettings();
|
||||
|
@ -546,11 +546,11 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg)
|
|||
title.append(QString(" - %1").arg(url().host()));
|
||||
}
|
||||
|
||||
CheckBoxDialog dialog(QDialogButtonBox::Ok, view());
|
||||
CheckBoxDialog dialog(QMessageBox::Ok, view());
|
||||
dialog.setWindowTitle(title);
|
||||
dialog.setText(msg);
|
||||
dialog.setCheckBoxText(tr("Prevent this page from creating additional dialogs"));
|
||||
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxInformation));
|
||||
dialog.setIcon(QMessageBox::Information);
|
||||
dialog.exec();
|
||||
|
||||
m_blockAlerts = dialog.isChecked();
|
||||
|
|
Loading…
Reference in New Issue
Block a user