From 4ac521354dfa575c31ecb732a0f8c1e18827c21e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 23 Nov 2012 14:27:50 +0100 Subject: QtBase: example code style Change-Id: I0685f7e2c7c698a4bf288b8b1ae909167932a3fb Reviewed-by: hjk --- examples/dbus/dbus-chat/chat.cpp | 6 ++--- examples/dbus/dbus-chat/chat.h | 6 ++--- examples/threads/mandelbrot/main.cpp | 4 ++-- examples/threads/mandelbrot/mandelbrotwidget.cpp | 15 +++++------- examples/threads/mandelbrot/mandelbrotwidget.h | 2 +- examples/threads/mandelbrot/renderthread.cpp | 4 ++-- examples/threads/mandelbrot/renderthread.h | 5 ++-- examples/widgets/desktop/screenshot/screenshot.cpp | 27 ++++++++-------------- examples/widgets/desktop/screenshot/screenshot.h | 5 ++-- examples/widgets/desktop/systray/window.cpp | 9 +++----- .../draganddrop/draggableicons/dragwidget.cpp | 4 ++-- .../draganddrop/draggableicons/dragwidget.h | 4 ++-- .../widgets/draganddrop/draggableicons/main.cpp | 1 + .../draganddrop/draggabletext/draglabel.cpp | 2 -- .../widgets/draganddrop/draggabletext/draglabel.h | 2 +- .../draganddrop/draggabletext/dragwidget.cpp | 3 +-- .../widgets/draganddrop/draggabletext/dragwidget.h | 2 +- .../widgets/draganddrop/draggabletext/main.cpp | 1 + examples/widgets/draganddrop/dropsite/droparea.cpp | 5 ++-- examples/widgets/draganddrop/dropsite/droparea.h | 2 +- .../widgets/draganddrop/dropsite/dropsitewindow.h | 2 +- .../draganddrop/fridgemagnets/draglabel.cpp | 7 +++--- .../widgets/draganddrop/fridgemagnets/draglabel.h | 2 +- .../draganddrop/fridgemagnets/dragwidget.cpp | 4 ++-- .../widgets/draganddrop/fridgemagnets/dragwidget.h | 2 +- .../widgets/draganddrop/fridgemagnets/main.cpp | 1 + examples/widgets/draganddrop/puzzle/mainwindow.cpp | 15 ++++++------ examples/widgets/draganddrop/puzzle/mainwindow.h | 2 +- examples/widgets/draganddrop/puzzle/pieceslist.cpp | 15 +++++++----- examples/widgets/draganddrop/puzzle/pieceslist.h | 2 +- .../widgets/draganddrop/puzzle/puzzlewidget.cpp | 13 ++++++----- examples/widgets/draganddrop/puzzle/puzzlewidget.h | 2 +- 32 files changed, 83 insertions(+), 93 deletions(-) diff --git a/examples/dbus/dbus-chat/chat.cpp b/examples/dbus/dbus-chat/chat.cpp index 496e1d7705..febb1da90c 100644 --- a/examples/dbus/dbus-chat/chat.cpp +++ b/examples/dbus/dbus-chat/chat.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include "chat.h" -#include -#include +#include +#include +#include "chat.h" #include "chat_adaptor.h" #include "chat_interface.h" diff --git a/examples/dbus/dbus-chat/chat.h b/examples/dbus/dbus-chat/chat.h index 8f7cdfabd2..fd73d6d227 100644 --- a/examples/dbus/dbus-chat/chat.h +++ b/examples/dbus/dbus-chat/chat.h @@ -41,8 +41,8 @@ #ifndef CHAT_H #define CHAT_H -#include -#include +#include + #include "ui_chatmainwindow.h" #include "ui_chatsetnickname.h" @@ -78,4 +78,4 @@ public: NicknameDialog(QWidget *parent = 0); }; -#endif +#endif // CHAT_H diff --git a/examples/threads/mandelbrot/main.cpp b/examples/threads/mandelbrot/main.cpp index 3800d2bbb1..cfb28fe093 100644 --- a/examples/threads/mandelbrot/main.cpp +++ b/examples/threads/mandelbrot/main.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "mandelbrotwidget.h" +#include + //! [0] int main(int argc, char *argv[]) { diff --git a/examples/threads/mandelbrot/mandelbrotwidget.cpp b/examples/threads/mandelbrot/mandelbrotwidget.cpp index 31cdceca18..c1ec029548 100644 --- a/examples/threads/mandelbrot/mandelbrotwidget.cpp +++ b/examples/threads/mandelbrot/mandelbrotwidget.cpp @@ -38,7 +38,8 @@ ** ****************************************************************************/ -#include +#include +#include #include @@ -65,8 +66,7 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) curScale = DefaultScale; qRegisterMetaType("QImage"); - connect(&thread, SIGNAL(renderedImage(QImage,double)), - this, SLOT(updatePixmap(QImage,double))); + connect(&thread, SIGNAL(renderedImage(QImage,double)), this, SLOT(updatePixmap(QImage,double))); setWindowTitle(tr("Mandelbrot")); #ifndef QT_NO_CURSOR @@ -85,8 +85,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) if (pixmap.isNull()) { painter.setPen(Qt::white); - painter.drawText(rect(), Qt::AlignCenter, - tr("Rendering initial image, please wait...")); + painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); //! [2] //! [3] return; //! [3] //! [4] @@ -122,11 +121,9 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); - painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, - metrics.lineSpacing() + 5); + painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); - painter.drawText((width() - textWidth) / 2, - metrics.leading() + metrics.ascent(), text); + painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); } //! [9] diff --git a/examples/threads/mandelbrot/mandelbrotwidget.h b/examples/threads/mandelbrot/mandelbrotwidget.h index 6306c28adc..ea5fdc53c1 100644 --- a/examples/threads/mandelbrot/mandelbrotwidget.h +++ b/examples/threads/mandelbrot/mandelbrotwidget.h @@ -81,4 +81,4 @@ private: }; //! [0] -#endif +#endif // MANDELBROTWIDGET_H diff --git a/examples/threads/mandelbrot/renderthread.cpp b/examples/threads/mandelbrot/renderthread.cpp index 9d4b199912..ea4c18f88b 100644 --- a/examples/threads/mandelbrot/renderthread.cpp +++ b/examples/threads/mandelbrot/renderthread.cpp @@ -38,12 +38,12 @@ ** ****************************************************************************/ +#include "renderthread.h" + #include #include -#include "renderthread.h" - //! [0] RenderThread::RenderThread(QObject *parent) : QThread(parent) diff --git a/examples/threads/mandelbrot/renderthread.h b/examples/threads/mandelbrot/renderthread.h index 61308f8b05..c292c0a676 100644 --- a/examples/threads/mandelbrot/renderthread.h +++ b/examples/threads/mandelbrot/renderthread.h @@ -59,8 +59,7 @@ public: RenderThread(QObject *parent = 0); ~RenderThread(); - void render(double centerX, double centerY, double scaleFactor, - QSize resultSize); + void render(double centerX, double centerY, double scaleFactor, QSize resultSize); signals: void renderedImage(const QImage &image, double scaleFactor); @@ -85,4 +84,4 @@ private: }; //! [0] -#endif +#endif // RENDERTHREAD_H diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp index 41f219c489..6fbbb8e32b 100644 --- a/examples/widgets/desktop/screenshot/screenshot.cpp +++ b/examples/widgets/desktop/screenshot/screenshot.cpp @@ -46,8 +46,7 @@ Screenshot::Screenshot() { screenshotLabel = new QLabel; - screenshotLabel->setSizePolicy(QSizePolicy::Expanding, - QSizePolicy::Expanding); + screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); screenshotLabel->setAlignment(Qt::AlignCenter); screenshotLabel->setMinimumSize(240, 160); @@ -73,8 +72,7 @@ void Screenshot::resizeEvent(QResizeEvent * /* event */) { QSize scaledSize = originalPixmap.size(); scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio); - if (!screenshotLabel->pixmap() - || scaledSize != screenshotLabel->pixmap()->size()) + if (!screenshotLabel->pixmap() || scaledSize != screenshotLabel->pixmap()->size()) updateScreenshotLabel(); } //! [1] @@ -96,11 +94,10 @@ void Screenshot::saveScreenshot() QString format = "png"; QString initialPath = QDir::currentPath() + tr("/untitled.") + format; - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), - initialPath, - tr("%1 Files (*.%2);;All Files (*)") - .arg(format.toUpper()) - .arg(format)); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), initialPath, + tr("%1 Files (*.%2);;All Files (*)") + .arg(format.toUpper()) + .arg(format)); if (!fileName.isEmpty()) originalPixmap.save(fileName, format.toLatin1().constData()); } @@ -132,9 +129,9 @@ void Screenshot::updateCheckBox() if (delaySpinBox->value() == 0) { hideThisWindowCheckBox->setDisabled(true); hideThisWindowCheckBox->setChecked(false); - } - else + } else { hideThisWindowCheckBox->setDisabled(false); + } } //! [6] @@ -163,12 +160,8 @@ void Screenshot::createOptionsGroupBox() //! [8] void Screenshot::createButtonsLayout() { - newScreenshotButton = createButton(tr("New Screenshot"), - this, SLOT(newScreenshot())); - - saveScreenshotButton = createButton(tr("Save Screenshot"), - this, SLOT(saveScreenshot())); - + newScreenshotButton = createButton(tr("New Screenshot"), this, SLOT(newScreenshot())); + saveScreenshotButton = createButton(tr("Save Screenshot"), this, SLOT(saveScreenshot())); quitScreenshotButton = createButton(tr("Quit"), this, SLOT(close())); buttonsLayout = new QHBoxLayout; diff --git a/examples/widgets/desktop/screenshot/screenshot.h b/examples/widgets/desktop/screenshot/screenshot.h index 22b98415bf..5defdc6d6a 100644 --- a/examples/widgets/desktop/screenshot/screenshot.h +++ b/examples/widgets/desktop/screenshot/screenshot.h @@ -75,8 +75,7 @@ private slots: private: void createOptionsGroupBox(); void createButtonsLayout(); - QPushButton *createButton(const QString &text, QWidget *receiver, - const char *member); + QPushButton *createButton(const QString &text, QWidget *receiver, const char *member); void updateScreenshotLabel(); QPixmap originalPixmap; @@ -96,4 +95,4 @@ private: }; //! [0] -#endif +#endif // SCREENSHOT_H diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp index af56f47595..8de1f5843e 100644 --- a/examples/widgets/desktop/systray/window.cpp +++ b/examples/widgets/desktop/systray/window.cpp @@ -66,10 +66,8 @@ Window::Window() createTrayIcon(); connect(showMessageButton, SIGNAL(clicked()), this, SLOT(showMessage())); - connect(showIconCheckBox, SIGNAL(toggled(bool)), - trayIcon, SLOT(setVisible(bool))); - connect(iconComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(setIcon(int))); + connect(showIconCheckBox, SIGNAL(toggled(bool)), trayIcon, SLOT(setVisible(bool))); + connect(iconComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setIcon(int))); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); @@ -129,8 +127,7 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) switch (reason) { case QSystemTrayIcon::Trigger: case QSystemTrayIcon::DoubleClick: - iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) - % iconComboBox->count()); + iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) % iconComboBox->count()); break; case QSystemTrayIcon::MiddleClick: showMessage(); diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp index 2422911fac..b9441f8a8a 100644 --- a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp +++ b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp @@ -159,9 +159,9 @@ void DragWidget::mousePressEvent(QMouseEvent *event) child->setPixmap(tempPixmap); - if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) + if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) { child->close(); - else { + } else { child->show(); child->setPixmap(pixmap); } diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.h b/examples/widgets/draganddrop/draggableicons/dragwidget.h index b6154430fe..dcacec8e3d 100644 --- a/examples/widgets/draganddrop/draggableicons/dragwidget.h +++ b/examples/widgets/draganddrop/draggableicons/dragwidget.h @@ -52,7 +52,7 @@ QT_END_NAMESPACE class DragWidget : public QFrame { public: - DragWidget(QWidget *parent=0); + DragWidget(QWidget *parent = 0); protected: void dragEnterEvent(QDragEnterEvent *event); @@ -62,4 +62,4 @@ protected: }; //! [0] -#endif +#endif // DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/draggableicons/main.cpp b/examples/widgets/draganddrop/draggableicons/main.cpp index 6e1110b1f3..03798b8e40 100644 --- a/examples/widgets/draganddrop/draggableicons/main.cpp +++ b/examples/widgets/draganddrop/draggableicons/main.cpp @@ -40,6 +40,7 @@ #include #include + #include "dragwidget.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/draganddrop/draggabletext/draglabel.cpp b/examples/widgets/draganddrop/draggabletext/draglabel.cpp index cd9d5ba09e..0f50f19fa2 100644 --- a/examples/widgets/draganddrop/draggabletext/draglabel.cpp +++ b/examples/widgets/draganddrop/draggabletext/draglabel.cpp @@ -38,8 +38,6 @@ ** ****************************************************************************/ -#include - #include "draglabel.h" DragLabel::DragLabel(const QString &text, QWidget *parent) diff --git a/examples/widgets/draganddrop/draggabletext/draglabel.h b/examples/widgets/draganddrop/draggabletext/draglabel.h index 404e1fbecf..3921f6bb1f 100644 --- a/examples/widgets/draganddrop/draggabletext/draglabel.h +++ b/examples/widgets/draganddrop/draggabletext/draglabel.h @@ -55,4 +55,4 @@ public: DragLabel(const QString &text, QWidget *parent); }; -#endif +#endif // DRAGLABEL_H diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp index 98e73701b3..5424b9a741 100644 --- a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp +++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp @@ -147,8 +147,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event) QMimeData *mimeData = new QMimeData; mimeData->setText(child->text()); mimeData->setData("application/x-hotspot", - QByteArray::number(hotSpot.x()) - + " " + QByteArray::number(hotSpot.y())); + QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y())); QPixmap pixmap(child->size()); child->render(&pixmap); diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.h b/examples/widgets/draganddrop/draggabletext/dragwidget.h index 77b44c07f1..dd222489c9 100644 --- a/examples/widgets/draganddrop/draggabletext/dragwidget.h +++ b/examples/widgets/draganddrop/draggabletext/dragwidget.h @@ -59,4 +59,4 @@ protected: void mousePressEvent(QMouseEvent *event); }; -#endif +#endif // DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/draggabletext/main.cpp b/examples/widgets/draganddrop/draggabletext/main.cpp index 126484a6a5..c68d251224 100644 --- a/examples/widgets/draganddrop/draggabletext/main.cpp +++ b/examples/widgets/draganddrop/draggabletext/main.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ #include + #include "dragwidget.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp index e4c087852a..9982529d98 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.cpp +++ b/examples/widgets/draganddrop/dropsite/droparea.cpp @@ -38,10 +38,11 @@ ** ****************************************************************************/ -#include - #include "droparea.h" +#include +#include + //! [DropArea constructor] DropArea::DropArea(QWidget *parent) : QLabel(parent) diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h index ac66182a70..8784090325 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.h +++ b/examples/widgets/draganddrop/dropsite/droparea.h @@ -74,4 +74,4 @@ private: }; //! [DropArea header part2] -#endif +#endif // DROPAREA_H diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h index a4aeaf4fc5..45fdd36d3f 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h @@ -74,4 +74,4 @@ private: }; //! [DropSiteWindow header] -#endif +#endif // DROPSITEWINDOW_H diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp index 327929132b..004ebd3fe5 100644 --- a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp +++ b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "draglabel.h" +#include + //! [0] DragLabel::DragLabel(const QString &text, QWidget *parent) : QLabel(parent) @@ -49,8 +49,7 @@ DragLabel::DragLabel(const QString &text, QWidget *parent) QFontMetrics metric(font()); QSize size = metric.size(Qt::TextSingleLine, text); - QImage image(size.width() + 12, size.height() + 12, - QImage::Format_ARGB32_Premultiplied); + QImage image(size.width() + 12, size.height() + 12, QImage::Format_ARGB32_Premultiplied); image.fill(qRgba(0, 0, 0, 0)); QFont font; diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.h b/examples/widgets/draganddrop/fridgemagnets/draglabel.h index c659a3a81f..e1fa2a2ba4 100644 --- a/examples/widgets/draganddrop/fridgemagnets/draglabel.h +++ b/examples/widgets/draganddrop/fridgemagnets/draglabel.h @@ -61,4 +61,4 @@ private: }; //! [0] -#endif +#endif // DRAGLABEL_H diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp index e45db9ec96..3aa8855ae1 100644 --- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp +++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp @@ -38,11 +38,11 @@ ** ****************************************************************************/ -#include - #include "draglabel.h" #include "dragwidget.h" +#include + //! [0] DragWidget::DragWidget(QWidget *parent) : QWidget(parent) diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h index 150702376e..851803affa 100644 --- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h +++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h @@ -62,4 +62,4 @@ protected: }; //! [0] -#endif +#endif // DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/fridgemagnets/main.cpp b/examples/widgets/draganddrop/fridgemagnets/main.cpp index 6ba0e42554..6eee38460a 100644 --- a/examples/widgets/draganddrop/fridgemagnets/main.cpp +++ b/examples/widgets/draganddrop/fridgemagnets/main.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ #include + #include "dragwidget.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.cpp b/examples/widgets/draganddrop/puzzle/mainwindow.cpp index 47300f3f28..bc0f4d6838 100644 --- a/examples/widgets/draganddrop/puzzle/mainwindow.cpp +++ b/examples/widgets/draganddrop/puzzle/mainwindow.cpp @@ -38,13 +38,13 @@ ** ****************************************************************************/ -#include -#include - #include "mainwindow.h" #include "pieceslist.h" #include "puzzlewidget.h" +#include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { @@ -59,9 +59,10 @@ void MainWindow::openImage(const QString &path) { QString fileName = path; - if (fileName.isNull()) + if (fileName.isNull()) { fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", "Image Files (*.png *.jpg *.bmp)"); + } if (!fileName.isEmpty()) { QPixmap newImage; @@ -79,9 +80,9 @@ void MainWindow::openImage(const QString &path) void MainWindow::setCompleted() { QMessageBox::information(this, tr("Puzzle Completed"), - tr("Congratulations! You have completed the puzzle!\n" - "Click OK to start again."), - QMessageBox::Ok); + tr("Congratulations! You have completed the puzzle!\n" + "Click OK to start again."), + QMessageBox::Ok); setupPuzzle(); } diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.h b/examples/widgets/draganddrop/puzzle/mainwindow.h index 3283bea39c..c975f50243 100644 --- a/examples/widgets/draganddrop/puzzle/mainwindow.h +++ b/examples/widgets/draganddrop/puzzle/mainwindow.h @@ -73,4 +73,4 @@ private: PuzzleWidget *puzzleWidget; }; -#endif +#endif // MAINWINDOW_H diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.cpp b/examples/widgets/draganddrop/puzzle/pieceslist.cpp index eab48b3562..434d5a0344 100644 --- a/examples/widgets/draganddrop/puzzle/pieceslist.cpp +++ b/examples/widgets/draganddrop/puzzle/pieceslist.cpp @@ -38,10 +38,12 @@ ** ****************************************************************************/ -#include - #include "pieceslist.h" +#include +#include +#include + PiecesList::PiecesList(int pieceSize, QWidget *parent) : QListWidget(parent), m_PieceSize(pieceSize) { @@ -66,8 +68,9 @@ void PiecesList::dragMoveEvent(QDragMoveEvent *event) if (event->mimeData()->hasFormat("image/x-puzzle-piece")) { event->setDropAction(Qt::MoveAction); event->accept(); - } else + } else { event->ignore(); + } } void PiecesList::dropEvent(QDropEvent *event) @@ -83,8 +86,9 @@ void PiecesList::dropEvent(QDropEvent *event) event->setDropAction(Qt::MoveAction); event->accept(); - } else + } else { event->ignore(); + } } void PiecesList::addPiece(QPixmap pixmap, QPoint location) @@ -93,8 +97,7 @@ void PiecesList::addPiece(QPixmap pixmap, QPoint location) pieceItem->setIcon(QIcon(pixmap)); pieceItem->setData(Qt::UserRole, QVariant(pixmap)); pieceItem->setData(Qt::UserRole+1, location); - pieceItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable - | Qt::ItemIsDragEnabled); + pieceItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); } void PiecesList::startDrag(Qt::DropActions /*supportedActions*/) diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h index 7824654a8d..19fa27a72a 100644 --- a/examples/widgets/draganddrop/puzzle/pieceslist.h +++ b/examples/widgets/draganddrop/puzzle/pieceslist.h @@ -60,4 +60,4 @@ protected: int m_PieceSize; }; -#endif +#endif // PIECESLIST_H diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp index 3798b2ec7b..f48ef08745 100644 --- a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp +++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp @@ -38,10 +38,13 @@ ** ****************************************************************************/ -#include - #include "puzzlewidget.h" +#include +#include +#include +#include + PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent) : QWidget(parent), m_ImageSize(imageSize) { @@ -130,9 +133,8 @@ void PuzzleWidget::dropEvent(QDropEvent *event) int PuzzleWidget::findPiece(const QRect &pieceRect) const { for (int i = 0; i < pieceRects.size(); ++i) { - if (pieceRect == pieceRects[i]) { + if (pieceRect == pieceRects[i]) return i; - } } return -1; } @@ -192,9 +194,8 @@ void PuzzleWidget::paintEvent(QPaintEvent *event) painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1)); } - for (int i = 0; i < pieceRects.size(); ++i) { + for (int i = 0; i < pieceRects.size(); ++i) painter.drawPixmap(pieceRects[i], piecePixmaps[i]); - } painter.end(); } diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h index 996c0aa184..6322eec93e 100644 --- a/examples/widgets/draganddrop/puzzle/puzzlewidget.h +++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.h @@ -86,4 +86,4 @@ private: int m_ImageSize; }; -#endif +#endif // PUZZLEWIDGET_H -- cgit v1.2.3