Commit fe1ea010 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Polish rich text example.


- Introduce Qt 5 signals & slot syntax.
- Use mime types in the file dialogs.
- Streamline the code creating the actions.
- Introduce QCommandLineParser.
- Query the available size when determining
  the initial size instead of using hard-coded values
  for High-DPI screens.

Change-Id: Ifc84a41ed55a4a674b6eafdb6120ac42441405b6
Reviewed-by: default avatarTopi Reiniö <topi.reinio@digia.com>
Showing with 196 additions and 221 deletions
......@@ -32,15 +32,37 @@
****************************************************************************/
#include "textedit.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QCommandLineParser>
#include <QCommandLineOption>
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(textedit);
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("QtProject");
QCoreApplication::setApplicationName("Rich Text");
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName());
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", "The file to open.");
parser.process(a);
TextEdit mw;
mw.resize(700, 800);
const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mw);
mw.resize(availableGeometry.width() / 2, (availableGeometry.height() * 2) / 3);
mw.move((availableGeometry.width() - mw.width()) / 2,
(availableGeometry.height() - mw.height()) / 2);
if (!mw.load(parser.positionalArguments().value(0, QLatin1String(":/example.html"))))
mw.fileNew();
mw.show();
return a.exec();
}
This diff is collapsed.
......@@ -55,19 +55,15 @@ class TextEdit : public QMainWindow
public:
TextEdit(QWidget *parent = 0);
bool load(const QString &f);
public slots:
void fileNew();
protected:
virtual void closeEvent(QCloseEvent *e) Q_DECL_OVERRIDE;
private:
void setupFileActions();
void setupEditActions();
void setupTextActions();
bool load(const QString &f);
bool maybeSave();
void setCurrentFileName(const QString &fileName);
private slots:
void fileNew();
void fileOpen();
bool fileSave();
bool fileSaveAs();
......@@ -92,6 +88,12 @@ private slots:
void printPreview(QPrinter *);
private:
void setupFileActions();
void setupEditActions();
void setupTextActions();
bool maybeSave();
void setCurrentFileName(const QString &fileName);
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
void colorChanged(const QColor &c);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment