examples/activeqt/menus/menus.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the examples of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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 }