| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the examples of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** 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 are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include "menus.h" | 
|---|
| 43 | #include <QAction> | 
|---|
| 44 | #include <QAxFactory> | 
|---|
| 45 | #include <QMenuBar> | 
|---|
| 46 | #include <QMessageBox> | 
|---|
| 47 | #include <QTextEdit> | 
|---|
| 48 | #include <QPixmap> | 
|---|
| 49 |  | 
|---|
| 50 | #include "fileopen.xpm" | 
|---|
| 51 | #include "filesave.xpm" | 
|---|
| 52 |  | 
|---|
| 53 | QMenus::QMenus(QWidget *parent) | 
|---|
| 54 | : QMainWindow(parent, 0) // QMainWindow's default flag is WType_TopLevel | 
|---|
| 55 | { | 
|---|
| 56 | QAction *action; | 
|---|
| 57 |  | 
|---|
| 58 | QMenu *file = new QMenu(this); | 
|---|
| 59 |  | 
|---|
| 60 | action = new QAction(QPixmap((const char**)fileopen), "&Open", this); | 
|---|
| 61 | action->setShortcut(tr("CTRL+O")); | 
|---|
| 62 | connect(action, SIGNAL(triggered()), this, SLOT(fileOpen())); | 
|---|
| 63 | file->addAction(action); | 
|---|
| 64 |  | 
|---|
| 65 | action = new QAction(QPixmap((const char**)filesave),"&Save", this); | 
|---|
| 66 | action->setShortcut(tr("CTRL+S")); | 
|---|
| 67 | connect(action, SIGNAL(triggered()), this, SLOT(fileSave())); | 
|---|
| 68 | file->addAction(action); | 
|---|
| 69 |  | 
|---|
| 70 | QMenu *edit = new QMenu(this); | 
|---|
| 71 |  | 
|---|
| 72 | action = new QAction("&Normal", this); | 
|---|
| 73 | action->setShortcut(tr("CTRL+N")); | 
|---|
| 74 | action->setToolTip("Normal"); | 
|---|
| 75 | action->setStatusTip("Toggles Normal"); | 
|---|
| 76 | action->setCheckable(true); | 
|---|
| 77 | connect(action, SIGNAL(triggered()), this, SLOT(editNormal())); | 
|---|
| 78 | edit->addAction(action); | 
|---|
| 79 |  | 
|---|
| 80 | action = new QAction("&Bold", this); | 
|---|
| 81 | action->setShortcut(tr("CTRL+B")); | 
|---|
| 82 | action->setCheckable(true); | 
|---|
| 83 | connect(action, SIGNAL(triggered()), this, SLOT(editBold())); | 
|---|
| 84 | edit->addAction(action); | 
|---|
| 85 |  | 
|---|
| 86 | action = new QAction("&Underline", this); | 
|---|
| 87 | action->setShortcut(tr("CTRL+U")); | 
|---|
| 88 | action->setCheckable(true); | 
|---|
| 89 | connect(action, SIGNAL(triggered()), this, SLOT(editUnderline())); | 
|---|
| 90 | edit->addAction(action); | 
|---|
| 91 |  | 
|---|
| 92 | QMenu *advanced = new QMenu(this); | 
|---|
| 93 | action = new QAction("&Font...", this); | 
|---|
| 94 | connect(action, SIGNAL(triggered()), this, SLOT(editAdvancedFont())); | 
|---|
| 95 | advanced->addAction(action); | 
|---|
| 96 |  | 
|---|
| 97 | action = new QAction("&Style...", this); | 
|---|
| 98 | connect(action, SIGNAL(triggered()), this, SLOT(editAdvancedStyle())); | 
|---|
| 99 | advanced->addAction(action); | 
|---|
| 100 |  | 
|---|
| 101 | edit->addMenu(advanced)->setText("&Advanced"); | 
|---|
| 102 |  | 
|---|
| 103 | edit->addSeparator(); | 
|---|
| 104 |  | 
|---|
| 105 | action = new QAction("Una&vailable", this); | 
|---|
| 106 | action->setShortcut(tr("CTRL+V")); | 
|---|
| 107 | action->setCheckable(true); | 
|---|
| 108 | action->setEnabled(false); | 
|---|
| 109 | connect(action, SIGNAL(triggered()), this, SLOT(editUnderline())); | 
|---|
| 110 | edit->addAction(action); | 
|---|
| 111 |  | 
|---|
| 112 | QMenu *help = new QMenu(this); | 
|---|
| 113 |  | 
|---|
| 114 | action = new QAction("&About...", this); | 
|---|
| 115 | action->setShortcut(tr("F1")); | 
|---|
| 116 | connect(action, SIGNAL(triggered()), this, SLOT(helpAbout())); | 
|---|
| 117 | help->addAction(action); | 
|---|
| 118 |  | 
|---|
| 119 | action = new QAction("&About Qt...", this); | 
|---|
| 120 | connect(action, SIGNAL(triggered()), this, SLOT(helpAboutQt())); | 
|---|
| 121 | help->addAction(action); | 
|---|
| 122 |  | 
|---|
| 123 | if (!QAxFactory::isServer()) | 
|---|
| 124 | menuBar()->addMenu(file)->setText("&File"); | 
|---|
| 125 | menuBar()->addMenu(edit)->setText("&Edit"); | 
|---|
| 126 | menuBar()->addMenu(help)->setText("&Help"); | 
|---|
| 127 |  | 
|---|
| 128 | editor = new QTextEdit(this); | 
|---|
| 129 | setCentralWidget(editor); | 
|---|
| 130 |  | 
|---|
| 131 | statusBar(); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | void QMenus::fileOpen() | 
|---|
| 135 | { | 
|---|
| 136 | editor->append("File Open selected."); | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | void QMenus::fileSave() | 
|---|
| 140 | { | 
|---|
| 141 | editor->append("File Save selected."); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | void QMenus::editNormal() | 
|---|
| 145 | { | 
|---|
| 146 | editor->append("Edit Normal selected."); | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 | void QMenus::editBold() | 
|---|
| 150 | { | 
|---|
| 151 | editor->append("Edit Bold selected."); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | void QMenus::editUnderline() | 
|---|
| 155 | { | 
|---|
| 156 | editor->append("Edit Underline selected."); | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | void QMenus::editAdvancedFont() | 
|---|
| 160 | { | 
|---|
| 161 | editor->append("Edit Advanced Font selected."); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | void QMenus::editAdvancedStyle() | 
|---|
| 165 | { | 
|---|
| 166 | editor->append("Edit Advanced Style selected."); | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | void QMenus::helpAbout() | 
|---|
| 170 | { | 
|---|
| 171 | QMessageBox::about(this, "About QMenus", | 
|---|
| 172 | "This example implements an in-place ActiveX control with menus and status messages."); | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | void QMenus::helpAboutQt() | 
|---|
| 176 | { | 
|---|
| 177 | QMessageBox::aboutQt(this); | 
|---|
| 178 | } | 
|---|