From a41534cbabd0aee90c38b9a1a133835863a7f54b Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 20 May 2010 11:29:20 +0200 Subject: Examples: Fix compilation with namespace. --- demos/spectrum/app/engine.h | 5 ++++- demos/spectrum/app/mainwidget.h | 3 +++ demos/spectrum/app/settingsdialog.h | 2 ++ demos/spectrum/app/spectrograph.h | 2 ++ demos/spectrum/app/spectrumanalyser.h | 3 +++ demos/spectrum/app/tonegenerator.h | 2 ++ demos/spectrum/app/tonegeneratordialog.h | 2 ++ demos/spectrum/app/utils.h | 2 ++ demos/spectrum/app/waveform.h | 2 ++ 9 files changed, 22 insertions(+), 1 deletion(-) diff --git a/demos/spectrum/app/engine.h b/demos/spectrum/app/engine.h index 16088b2..93733fe 100644 --- a/demos/spectrum/app/engine.h +++ b/demos/spectrum/app/engine.h @@ -61,10 +61,13 @@ #include #endif +QT_BEGIN_NAMESPACE class QAudioInput; class QAudioOutput; -class FrequencySpectrum; class QFile; +QT_END_NAMESPACE + +class FrequencySpectrum; /** * This class interfaces with the QtMultimedia audio classes, and also with diff --git a/demos/spectrum/app/mainwidget.h b/demos/spectrum/app/mainwidget.h index 846b97a..c59dbd6 100644 --- a/demos/spectrum/app/mainwidget.h +++ b/demos/spectrum/app/mainwidget.h @@ -50,11 +50,14 @@ class Waveform; class LevelMeter; class SettingsDialog; class ToneGeneratorDialog; + +QT_BEGIN_NAMESPACE class QAudioFormat; class QLabel; class QPushButton; class QMenu; class QAction; +QT_END_NAMESPACE /** * Main application widget, responsible for connecting the various UI diff --git a/demos/spectrum/app/settingsdialog.h b/demos/spectrum/app/settingsdialog.h index 7215a50..fda518b 100644 --- a/demos/spectrum/app/settingsdialog.h +++ b/demos/spectrum/app/settingsdialog.h @@ -42,11 +42,13 @@ #include #include +QT_BEGIN_NAMESPACE class QComboBox; class QCheckBox; class QSlider; class QSpinBox; class QGridLayout; +QT_END_NAMESPACE /** * Dialog used to control settings such as the audio input / output device diff --git a/demos/spectrum/app/spectrograph.h b/demos/spectrum/app/spectrograph.h index 6bfef33..a7790ff 100644 --- a/demos/spectrum/app/spectrograph.h +++ b/demos/spectrum/app/spectrograph.h @@ -41,7 +41,9 @@ #include #include "frequencyspectrum.h" +QT_BEGIN_NAMESPACE class QMouseEvent; +QT_END_NAMESPACE /** * Widget which displays a spectrograph showing the frequency spectrum diff --git a/demos/spectrum/app/spectrumanalyser.h b/demos/spectrum/app/spectrumanalyser.h index caeb1c1..f10da63 100644 --- a/demos/spectrum/app/spectrumanalyser.h +++ b/demos/spectrum/app/spectrumanalyser.h @@ -55,8 +55,11 @@ #include "FFTRealFixLenParam.h" #endif +QT_BEGIN_NAMESPACE class QAudioFormat; class QThread; +QT_END_NAMESPACE + class FFTRealWrapper; class SpectrumAnalyserThreadPrivate; diff --git a/demos/spectrum/app/tonegenerator.h b/demos/spectrum/app/tonegenerator.h index 419f7e4..d387768 100644 --- a/demos/spectrum/app/tonegenerator.h +++ b/demos/spectrum/app/tonegenerator.h @@ -41,8 +41,10 @@ #include #include "spectrum.h" +QT_BEGIN_NAMESPACE class QAudioFormat; class QByteArray; +QT_END_NAMESPACE /** * Generate a sine wave diff --git a/demos/spectrum/app/tonegeneratordialog.h b/demos/spectrum/app/tonegeneratordialog.h index 35d69c2..d6fcffa 100644 --- a/demos/spectrum/app/tonegeneratordialog.h +++ b/demos/spectrum/app/tonegeneratordialog.h @@ -42,10 +42,12 @@ #include #include +QT_BEGIN_NAMESPACE class QCheckBox; class QSlider; class QSpinBox; class QGridLayout; +QT_END_NAMESPACE /** * Dialog which controls the parameters of the tone generator. diff --git a/demos/spectrum/app/utils.h b/demos/spectrum/app/utils.h index 83467cd..548f884 100644 --- a/demos/spectrum/app/utils.h +++ b/demos/spectrum/app/utils.h @@ -41,7 +41,9 @@ #include #include +QT_BEGIN_NAMESPACE class QAudioFormat; +QT_END_NAMESPACE //----------------------------------------------------------------------------- // Miscellaneous utility functions diff --git a/demos/spectrum/app/waveform.h b/demos/spectrum/app/waveform.h index 4de527f..909e5ee 100644 --- a/demos/spectrum/app/waveform.h +++ b/demos/spectrum/app/waveform.h @@ -43,7 +43,9 @@ #include #include +QT_BEGIN_NAMESPACE class QByteArray; +QT_END_NAMESPACE /** * Widget which displays a section of the audio waveform. -- cgit v0.12 From 16f44ee07db46ad362a464afc2c6e6567c933870 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 20 May 2010 10:52:16 +0200 Subject: QApplication::closeAllWindows() should ignore windows being closed It is very common to display a dialog in response to a close event. Closing the window again will result in QWidget::close() returning true. This confuses QApplication::closeAllWindows(), since the window is still visible even though it was closed (or is closing). Solve this by ignoring windows that have the is_closing flag set in their widget data. Task-number: QTBUG-7635 Reviewed-by: Denis Dzyubenko --- src/gui/kernel/qapplication.cpp | 8 +-- tests/auto/qapplication/tst_qapplication.cpp | 78 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 7b62de1..b805a72 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -2218,15 +2218,17 @@ void QApplication::closeAllWindows() { bool did_close = true; QWidget *w; - while((w = activeModalWidget()) && did_close) { - if(!w->isVisible()) + while ((w = activeModalWidget()) && did_close) { + if (!w->isVisible() || w->data->is_closing) break; did_close = w->close(); } QWidgetList list = QApplication::topLevelWidgets(); for (int i = 0; did_close && i < list.size(); ++i) { w = list.at(i); - if (w->isVisible() && w->windowType() != Qt::Desktop) { + if (w->isVisible() + && w->windowType() != Qt::Desktop + && !w->data->is_closing) { did_close = w->close(); list = QApplication::topLevelWidgets(); i = -1; diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp index 459ac2b..43fbba1 100644 --- a/tests/auto/qapplication/tst_qapplication.cpp +++ b/tests/auto/qapplication/tst_qapplication.cpp @@ -106,6 +106,7 @@ private slots: void lastWindowClosed(); void quitOnLastWindowClosed(); + void closeAllWindows(); void testDeleteLater(); void testDeleteLaterProcessEvents(); @@ -745,6 +746,83 @@ void tst_QApplication::quitOnLastWindowClosed() } } +class PromptOnCloseWidget : public QWidget +{ +public: + void closeEvent(QCloseEvent *event) + { + QMessageBox *messageBox = new QMessageBox(this); + messageBox->setWindowTitle("Unsaved data"); + messageBox->setText("Would you like to save or discard your current data?"); + messageBox->setStandardButtons(QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel); + messageBox->setDefaultButton(QMessageBox::Save); + + messageBox->show(); + QTest::qWaitForWindowShown(messageBox); + + // verify that all windows are visible + foreach (QWidget *w, qApp->topLevelWidgets()) + QVERIFY(w->isVisible()); + // flush event queue + qApp->processEvents(); + // close all windows + qApp->closeAllWindows(); + + if (messageBox->standardButton(messageBox->clickedButton()) == QMessageBox::Cancel) + event->ignore(); + else + event->accept(); + + delete messageBox; + } +}; + +void tst_QApplication::closeAllWindows() +{ + int argc = 0; + QApplication app(argc, 0, QApplication::GuiServer); + + // create some windows + new QWidget; + new QWidget; + new QWidget; + + // show all windows + foreach (QWidget *w, app.topLevelWidgets()) { + w->show(); + QTest::qWaitForWindowShown(w); + } + // verify that they are visible + foreach (QWidget *w, app.topLevelWidgets()) + QVERIFY(w->isVisible()); + // empty event queue + app.processEvents(); + // close all windows + app.closeAllWindows(); + // all windows should no longer be visible + foreach (QWidget *w, app.topLevelWidgets()) + QVERIFY(!w->isVisible()); + + // add a window that prompts the user when closed + PromptOnCloseWidget *promptOnCloseWidget = new PromptOnCloseWidget; + // show all windows + foreach (QWidget *w, app.topLevelWidgets()) { + w->show(); + QTest::qWaitForWindowShown(w); + } + // close the last window to open the prompt (eventloop recurses) + promptOnCloseWidget->close(); + // all windows should not be visible, except the one that opened the prompt + foreach (QWidget *w, app.topLevelWidgets()) { + if (w == promptOnCloseWidget) + QVERIFY(w->isVisible()); + else + QVERIFY(!w->isVisible()); + } + + qDeleteAll(app.topLevelWidgets()); +} + bool isPathListIncluded(const QStringList &l, const QStringList &r) { int size = r.count(); -- cgit v0.12 From 65a673f7ab1955e277246e4c88bec46493265cf3 Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Thu, 20 May 2010 12:17:58 +0200 Subject: QPushButton's click area exceeds the button area by far on Mac OS X The problem is the "rounding" of buttons in OSX. To achieve this we add some padding to the buttons, therefore creating an inner rect for the widget. The common hitButton(...) method found in QAbstractButton just checks the normal rect of the widget. What this patch does is to reimplement hitButton(...) in QPushButton, but only for the Mac case. In this reimplemented method I calculate the inner rect and check if the hit point is inside that rect or not. Task-number: QTBUG-10401 Reviewed-by: Richard Moe Gustavsen --- src/gui/styles/qmacstyle_mac.h | 11 +++++++++++ src/gui/styles/qmacstyle_mac.mm | 33 +++++++++++++++++---------------- src/gui/widgets/qpushbutton.cpp | 34 ++++++++++++++++++++++++++++++++++ src/gui/widgets/qpushbutton.h | 3 +++ src/gui/widgets/qpushbutton_p.h | 3 +++ 5 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/gui/styles/qmacstyle_mac.h b/src/gui/styles/qmacstyle_mac.h index bcebb1d..e594793 100644 --- a/src/gui/styles/qmacstyle_mac.h +++ b/src/gui/styles/qmacstyle_mac.h @@ -120,6 +120,17 @@ public: bool event(QEvent *e); + // Ideally these wouldn't exist, but since they already exist we need some accessors. + static const int PushButtonLeftOffset; + static const int PushButtonTopOffset; + static const int PushButtonRightOffset; + static const int PushButtonBottomOffset; + static const int MiniButtonH; + static const int SmallButtonH; + static const int BevelButtonW; + static const int BevelButtonH; + static const int PushButtonContentPadding; + protected Q_SLOTS: QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0, const QWidget *widget = 0) const; diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index e065bcc..0f01bd5 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -108,15 +108,15 @@ extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp // The following constants are used for adjusting the size // of push buttons so that they are drawn inside their bounds. -static const int PushButtonLeftOffset = 6; -static const int PushButtonTopOffset = 4; -static const int PushButtonRightOffset = 12; -static const int PushButtonBottomOffset = 12; -static const int MiniButtonH = 26; -static const int SmallButtonH = 30; -static const int BevelButtonW = 50; -static const int BevelButtonH = 22; -static const int PushButtonContentPadding = 6; +const int QMacStyle::PushButtonLeftOffset = 6; +const int QMacStyle::PushButtonTopOffset = 4; +const int QMacStyle::PushButtonRightOffset = 12; +const int QMacStyle::PushButtonBottomOffset = 12; +const int QMacStyle::MiniButtonH = 26; +const int QMacStyle::SmallButtonH = 30; +const int QMacStyle::BevelButtonW = 50; +const int QMacStyle::BevelButtonH = 22; +const int QMacStyle::PushButtonContentPadding = 6; // These colors specify the titlebar gradient colors on // Leopard. Ideally we should get them from the system. @@ -1055,10 +1055,10 @@ HIRect QMacStylePrivate::pushButtonContentBounds(const QStyleOptionButton *btn, // Adjust the bounds to correct for // carbon not calculating the content bounds fully correct if (bdi->kind == kThemePushButton || bdi->kind == kThemePushButtonSmall){ - outerBounds.origin.y += PushButtonTopOffset; - outerBounds.size.height -= PushButtonBottomOffset; + outerBounds.origin.y += QMacStyle::PushButtonTopOffset; + outerBounds.size.height -= QMacStyle::PushButtonBottomOffset; } else if (bdi->kind == kThemePushButtonMini) { - outerBounds.origin.y += PushButtonTopOffset; + outerBounds.origin.y += QMacStyle::PushButtonTopOffset; } HIRect contentBounds; @@ -1074,7 +1074,7 @@ QSize QMacStylePrivate::pushButtonSizeFromContents(const QStyleOptionButton *btn { QSize csz(0, 0); QSize iconSize = btn->icon.isNull() ? QSize(0, 0) - : (btn->iconSize + QSize(PushButtonContentPadding, 0)); + : (btn->iconSize + QSize(QMacStyle::PushButtonContentPadding, 0)); QRect textRect = btn->text.isEmpty() ? QRect(0, 0, 1, 1) : btn->fontMetrics.boundingRect(QRect(), Qt::AlignCenter, btn->text); csz.setWidth(iconSize.width() + textRect.width() @@ -1149,12 +1149,12 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, // Choose the button kind that closest match the button rect, but at the // same time displays the button contents without clipping. bdi->kind = kThemeBevelButton; - if (btn->rect.width() >= BevelButtonW && btn->rect.height() >= BevelButtonH){ + if (btn->rect.width() >= QMacStyle::BevelButtonW && btn->rect.height() >= QMacStyle::BevelButtonH){ if (widget && widget->testAttribute(Qt::WA_MacVariableSize)) { - if (btn->rect.height() <= MiniButtonH){ + if (btn->rect.height() <= QMacStyle::MiniButtonH){ if (contentFitsInPushButton(btn, bdi, kThemePushButtonMini)) bdi->kind = kThemePushButtonMini; - } else if (btn->rect.height() <= SmallButtonH){ + } else if (btn->rect.height() <= QMacStyle::SmallButtonH){ if (contentFitsInPushButton(btn, bdi, kThemePushButtonSmall)) bdi->kind = kThemePushButtonSmall; } else if (contentFitsInPushButton(btn, bdi, kThemePushButton)) { @@ -3470,6 +3470,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QCommonStyle::drawControl(ce, opt, p, w); break; case CE_PushButtonBevel: + qDebug() << "here"; if (const QStyleOptionButton *btn = ::qstyleoption_cast(opt)) { if (!(btn->state & (State_Raised | State_Sunken | State_On))) break; diff --git a/src/gui/widgets/qpushbutton.cpp b/src/gui/widgets/qpushbutton.cpp index 1a9adcc..7b8c0db 100644 --- a/src/gui/widgets/qpushbutton.cpp +++ b/src/gui/widgets/qpushbutton.cpp @@ -58,6 +58,9 @@ #include "qdebug.h" #include "qlayoutitem.h" #include "qdialogbuttonbox.h" +#ifdef Q_WS_MAC +#include "qmacstyle_mac.h" +#endif // Q_WS_MAC #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" @@ -679,6 +682,37 @@ bool QPushButton::event(QEvent *e) return QAbstractButton::event(e); } +#ifdef Q_WS_MAC +/*! \reimp */ +bool QPushButton::hitButton(const QPoint &pos) const +{ + // This is only required if we are using the native style, so check that first. + QMacStyle *macStyle = qobject_cast(style()); + // If this is a flat button we just bail out. + if(isFlat() || (0 == macStyle)) + return QAbstractButton::hitButton(pos); + // Now that we know we are using the native style, let's proceed. + Q_D(const QPushButton); + QPushButtonPrivate *nonConst = const_cast(d); + // In OSX buttons are round, which causes the hit method to be special. + // We cannot simply relay on detecting if something is inside the rect or not, + // we need to check if it is inside the "rounded area" or not. A point might + // be inside the rect but not inside the rounded area. + // Notice this method is only reimplemented for OSX. + return nonConst->hitButton(pos); +} + +bool QPushButtonPrivate::hitButton(const QPoint &pos) +{ + Q_Q(QPushButton); + QRect roundedRect(q->rect().left() + QMacStyle::PushButtonLeftOffset, + q->rect().top() + QMacStyle::PushButtonContentPadding, + q->rect().width() - QMacStyle::PushButtonRightOffset, + q->rect().height() - QMacStyle::PushButtonBottomOffset); + return roundedRect.contains(pos); +} +#endif // Q_WS_MAC + #ifdef QT3_SUPPORT /*! Use one of the constructors that doesn't take the \a name diff --git a/src/gui/widgets/qpushbutton.h b/src/gui/widgets/qpushbutton.h index 2a4823d..cf28753 100644 --- a/src/gui/widgets/qpushbutton.h +++ b/src/gui/widgets/qpushbutton.h @@ -91,6 +91,9 @@ public Q_SLOTS: protected: bool event(QEvent *e); +#ifdef Q_WS_MAC + bool hitButton(const QPoint &pos) const; +#endif // Q_WS_MAC void paintEvent(QPaintEvent *); void keyPressEvent(QKeyEvent *); void focusInEvent(QFocusEvent *); diff --git a/src/gui/widgets/qpushbutton_p.h b/src/gui/widgets/qpushbutton_p.h index f2ee09d..6feb726 100644 --- a/src/gui/widgets/qpushbutton_p.h +++ b/src/gui/widgets/qpushbutton_p.h @@ -69,6 +69,9 @@ public: inline void init() { resetLayoutItemMargins(); } static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } +#ifdef Q_WS_MAC + bool hitButton(const QPoint &pos); +#endif #ifndef QT_NO_MENU QPoint adjustedMenuPosition(); #endif -- cgit v0.12 From d88905544477283a17580b210e46c93635cf9920 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 20 May 2010 12:22:29 +0200 Subject: update 4.7.0 changes Mistakenly added something that was fixed for 4.6.3 (it's been moved to changes-4.6.3 in a different branch). --- dist/changes-4.7.0 | 2 -- 1 file changed, 2 deletions(-) diff --git a/dist/changes-4.7.0 b/dist/changes-4.7.0 index a57575e..d6209f4 100644 --- a/dist/changes-4.7.0 +++ b/dist/changes-4.7.0 @@ -54,8 +54,6 @@ QtCore * Significantly improved performance of the type() function - QState * [QTBUG-7741] Added a function to get the out-going transitions - - QStateMachine - * [QTBUG-8842] Reset history states when (re)starting machine - QXmlStreamReader * [QTBUG-9196] fixed crash when parsing - QTimer -- cgit v0.12