2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-02-11 12:37:56 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
|
|
|
** You may use this file under the terms of the BSD license as follows:
|
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
2015-02-13 11:22:41 +00:00
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
2012-09-20 06:20:30 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2012-01-24 02:57:36 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "menus.h"
|
|
|
|
#include <QAction>
|
|
|
|
#include <QAxFactory>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
#include "fileopen.xpm"
|
|
|
|
#include "filesave.xpm"
|
|
|
|
|
2014-01-15 21:17:52 +00:00
|
|
|
QMenus::QMenus(QWidget *parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
: QMainWindow(parent, 0) // QMainWindow's default flag is WType_TopLevel
|
|
|
|
{
|
|
|
|
QAction *action;
|
|
|
|
|
|
|
|
QMenu *file = new QMenu(this);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(QPixmap((const char**)fileopen), tr("&Open"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+O"));
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::fileOpen);
|
2011-04-27 10:05:43 +00:00
|
|
|
file->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(QPixmap((const char**)filesave), tr("&Save"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+S"));
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::fileSave);
|
2011-04-27 10:05:43 +00:00
|
|
|
file->addAction(action);
|
|
|
|
|
|
|
|
QMenu *edit = new QMenu(this);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&Normal"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+N"));
|
2017-08-21 11:23:48 +00:00
|
|
|
action->setToolTip(tr("Normal"));
|
|
|
|
action->setStatusTip(tr("Toggles Normal"));
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setCheckable(true);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editNormal);
|
2011-04-27 10:05:43 +00:00
|
|
|
edit->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&Bold"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+B"));
|
|
|
|
action->setCheckable(true);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editBold);
|
2011-04-27 10:05:43 +00:00
|
|
|
edit->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&Underline"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+U"));
|
|
|
|
action->setCheckable(true);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editUnderline);
|
2011-04-27 10:05:43 +00:00
|
|
|
edit->addAction(action);
|
|
|
|
|
|
|
|
QMenu *advanced = new QMenu(this);
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&Font..."), this);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editAdvancedFont);
|
2011-04-27 10:05:43 +00:00
|
|
|
advanced->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&Style..."), this);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editAdvancedStyle);
|
2011-04-27 10:05:43 +00:00
|
|
|
advanced->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
edit->addMenu(advanced)->setText(tr("&Advanced"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("Una&vailable"), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("CTRL+V"));
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setEnabled(false);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::editUnderline);
|
2011-04-27 10:05:43 +00:00
|
|
|
edit->addAction(action);
|
|
|
|
|
|
|
|
QMenu *help = new QMenu(this);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&About..."), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
action->setShortcut(tr("F1"));
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::helpAbout);
|
2011-04-27 10:05:43 +00:00
|
|
|
help->addAction(action);
|
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
action = new QAction(tr("&About Qt..."), this);
|
2014-12-17 13:02:29 +00:00
|
|
|
connect(action, &QAction::triggered, this, &QMenus::helpAboutQt);
|
2011-04-27 10:05:43 +00:00
|
|
|
help->addAction(action);
|
|
|
|
|
|
|
|
if (!QAxFactory::isServer())
|
2017-08-21 11:23:48 +00:00
|
|
|
menuBar()->addMenu(file)->setText(tr("&File"));
|
|
|
|
menuBar()->addMenu(edit)->setText(tr("&Edit"));
|
|
|
|
menuBar()->addMenu(help)->setText(tr("&Help"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor = new QTextEdit(this);
|
|
|
|
setCentralWidget(m_editor);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
statusBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::fileOpen()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("File Open selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::fileSave()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("File Save selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::editNormal()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("Edit Normal selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::editBold()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("Edit Bold selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::editUnderline()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("Edit Underline selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::editAdvancedFont()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("Edit Advanced Font selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::editAdvancedStyle()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
m_editor->append(tr("Edit Advanced Style selected."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::helpAbout()
|
|
|
|
{
|
2017-08-21 11:23:48 +00:00
|
|
|
QMessageBox::about(this, tr("About QMenus"),
|
|
|
|
tr("This example implements an in-place ActiveX control with menus and status messages."));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMenus::helpAboutQt()
|
|
|
|
{
|
|
|
|
QMessageBox::aboutQt(this);
|
|
|
|
}
|