source: trunk/examples/richtext/orderform/mainwindow.cpp@ 683

Last change on this file since 683 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "detailsdialog.h"
45#include "mainwindow.h"
46
47//! [0]
48MainWindow::MainWindow()
49{
50 QMenu *fileMenu = new QMenu(tr("&File"), this);
51 QAction *newAction = fileMenu->addAction(tr("&New..."));
52 newAction->setShortcuts(QKeySequence::New);
53 printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile()));
54 printAction->setShortcuts(QKeySequence::Print);
55 printAction->setEnabled(false);
56 QAction *quitAction = fileMenu->addAction(tr("E&xit"));
57 quitAction->setShortcuts(QKeySequence::Quit);
58 menuBar()->addMenu(fileMenu);
59
60 letters = new QTabWidget;
61
62 connect(newAction, SIGNAL(triggered()), this, SLOT(openDialog()));
63 connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
64
65 setCentralWidget(letters);
66 setWindowTitle(tr("Order Form"));
67}
68//! [0]
69
70//! [1]
71void MainWindow::createLetter(const QString &name, const QString &address,
72 QList<QPair<QString,int> > orderItems,
73 bool sendOffers)
74{
75 QTextEdit *editor = new QTextEdit;
76 int tabIndex = letters->addTab(editor, name);
77 letters->setCurrentIndex(tabIndex);
78//! [1]
79
80//! [2]
81 QTextCursor cursor(editor->textCursor());
82 cursor.movePosition(QTextCursor::Start);
83//! [2] //! [3]
84 QTextFrame *topFrame = cursor.currentFrame();
85 QTextFrameFormat topFrameFormat = topFrame->frameFormat();
86 topFrameFormat.setPadding(16);
87 topFrame->setFrameFormat(topFrameFormat);
88
89 QTextCharFormat textFormat;
90 QTextCharFormat boldFormat;
91 boldFormat.setFontWeight(QFont::Bold);
92
93 QTextFrameFormat referenceFrameFormat;
94 referenceFrameFormat.setBorder(1);
95 referenceFrameFormat.setPadding(8);
96 referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
97 referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 40));
98 cursor.insertFrame(referenceFrameFormat);
99
100 cursor.insertText("A company", boldFormat);
101 cursor.insertBlock();
102 cursor.insertText("321 City Street");
103 cursor.insertBlock();
104 cursor.insertText("Industry Park");
105 cursor.insertBlock();
106 cursor.insertText("Another country");
107//! [3]
108
109//! [4]
110 cursor.setPosition(topFrame->lastPosition());
111
112 cursor.insertText(name, textFormat);
113 QString line;
114 foreach (line, address.split("\n")) {
115 cursor.insertBlock();
116 cursor.insertText(line);
117 }