QtBase: example code style
Change-Id: I0685f7e2c7c698a4bf288b8b1ae909167932a3fb Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
parent
d5ec06be63
commit
4ac521354d
@ -38,10 +38,10 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "chat.h"
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "chat.h"
|
||||
#include "chat_adaptor.h"
|
||||
#include "chat_interface.h"
|
||||
|
||||
|
@ -41,8 +41,8 @@
|
||||
#ifndef CHAT_H
|
||||
#define CHAT_H
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QStringList>
|
||||
|
||||
#include "ui_chatmainwindow.h"
|
||||
#include "ui_chatsetnickname.h"
|
||||
|
||||
@ -78,4 +78,4 @@ public:
|
||||
NicknameDialog(QWidget *parent = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // CHAT_H
|
||||
|
@ -38,10 +38,10 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "mandelbrotwidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
//! [0]
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -38,7 +38,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QPainter>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@ -65,8 +66,7 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent)
|
||||
curScale = DefaultScale;
|
||||
|
||||
qRegisterMetaType<QImage>("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]
|
||||
|
||||
|
@ -81,4 +81,4 @@ private:
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
||||
#endif // MANDELBROTWIDGET_H
|
||||
|
@ -38,12 +38,12 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderthread.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "renderthread.h"
|
||||
|
||||
//! [0]
|
||||
RenderThread::RenderThread(QObject *parent)
|
||||
: QThread(parent)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "dragwidget.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -38,8 +38,6 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "draglabel.h"
|
||||
|
||||
DragLabel::DragLabel(const QString &text, QWidget *parent)
|
||||
|
@ -55,4 +55,4 @@ public:
|
||||
DragLabel(const QString &text, QWidget *parent);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // DRAGLABEL_H
|
||||
|
@ -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);
|
||||
|
@ -59,4 +59,4 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // DRAGWIDGET_H
|
||||
|
@ -39,6 +39,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "dragwidget.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -38,10 +38,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "droparea.h"
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
//! [DropArea constructor]
|
||||
DropArea::DropArea(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
|
@ -74,4 +74,4 @@ private:
|
||||
};
|
||||
//! [DropArea header part2]
|
||||
|
||||
#endif
|
||||
#endif // DROPAREA_H
|
||||
|
@ -74,4 +74,4 @@ private:
|
||||
};
|
||||
//! [DropSiteWindow header]
|
||||
|
||||
#endif
|
||||
#endif // DROPSITEWINDOW_H
|
||||
|
@ -38,10 +38,10 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "draglabel.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
//! [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;
|
||||
|
@ -61,4 +61,4 @@ private:
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
||||
#endif // DRAGLABEL_H
|
||||
|
@ -38,11 +38,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "draglabel.h"
|
||||
#include "dragwidget.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
//! [0]
|
||||
DragWidget::DragWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
@ -62,4 +62,4 @@ protected:
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
||||
#endif // DRAGWIDGET_H
|
||||
|
@ -39,6 +39,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "dragwidget.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -38,13 +38,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "pieceslist.h"
|
||||
#include "puzzlewidget.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <stdlib.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -73,4 +73,4 @@ private:
|
||||
PuzzleWidget *puzzleWidget;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -38,10 +38,12 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "pieceslist.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
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*/)
|
||||
|
@ -60,4 +60,4 @@ protected:
|
||||
int m_PieceSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // PIECESLIST_H
|
||||
|
@ -38,10 +38,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "puzzlewidget.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -86,4 +86,4 @@ private:
|
||||
int m_ImageSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // PUZZLEWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user