Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 604

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/examples/action/actiongroup/actiongroup.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A Tiny Example Featuring QActionGroup</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>A Tiny Example Featuring QActionGroup</h1>

 
<p> 
<p> This example program shows how to use an
exclusive action group.
<p> Detailed explanations of the code can be found in the
<a href="actiongroup.html">walkthrough</a>.
<p> <hr>
<p> Main:
<p> <pre>/*
$Id$
*/

#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;

#include "editor.h"

int main( int argc, char ** argv)
{
    <a href="qapplication.html">QApplication</a> app( argc, argv );
    Editor editor;
    editor.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Actiongroup" );
    app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;editor );
    editor.<a href="qwidget.html#show">show</a>();
    return app.<a href="qapplication.html#exec">exec</a>();
}
</pre>

<p> <hr>
<p> Header file:
<p> <pre>/*
$Id$
*/

#ifndef EDITOR_H
#define EDITOR_H

#include &lt;<a href="qmainwindow-h.html">qmainwindow.h</a>&gt;

class QTextEdit;
class QAction;

class Editor : public <a href="qmainwindow.html">QMainWindow</a>
{
    <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>

public:
    Editor();

private slots:
    void setFontColor( <a href="qaction.html">QAction</a> * );

private:
    <a href="qtextedit.html">QTextEdit</a> * editor;
    <a href="qaction.html">QAction</a> * setRedFont;
};

#endif
</pre>

<p> <hr>
<p> Implementation:
<p> <pre>/*
$Id$
*/

/* XPM */
static const char * black_xpm[] = {
"32 32 2 1",
"       c None",
".      c #020202",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................"};

/* XPM */
static const char * red_xpm[] = {
"32 32 6 1",
"       c None",
".      c #EE0928",
"+      c #EF0928",
"@      c #EE0A29",
"#      c #EE0B2A",
"$      c #ED0C2B",
"........................+.......",
".+.++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++.+++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
"+++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++.+++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++.+++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++@",
".+++++++++++++++++++++++++++++.#",
".+++++++++++++++++++++++++.+++.$",
".+++++++++++++++++++++++++++++#$",
".+++++++++++++++++++++++++++++.#",
".+++++++++++++++++++++++++++++.#",
".++++++++.+++++++++++++++++++++@",
".++++++.+++++++++++++++++++++++.",
".++++++++++++++++++++++++++++++.",
"..........+.............+......."};


#include "editor.h"

#include &lt;<a href="qtextedit-h.html">qtextedit.h</a>&gt;
#include &lt;<a href="qmenubar-h.html">qmenubar.h</a>&gt;
#include &lt;<a href="qpopupmenu-h.html">qpopupmenu.h</a>&gt;
#include &lt;<a href="qtoolbar-h.html">qtoolbar.h</a>&gt;
#include &lt;<a href="qaction-h.html">qaction.h</a>&gt;

<a name="f535"></a>Editor::Editor()
    : <a href="qmainwindow.html">QMainWindow</a>( 0, "main window")
{
    <a href="qactiongroup.html">QActionGroup</a> * colors = new <a href="qactiongroup.html">QActionGroup</a>( this, "colors", TRUE );

    <a href="qaction.html">QAction</a> * setBlackFont = new <a href="qaction.html">QAction</a>( "black", QPixmap( (const char**)black_xpm ),
                                          "Font color: black", CTRL+Key_B,
                                          colors, "blackfontcolor", TRUE );
    setRedFont = new <a href="qaction.html">QAction</a>( "red", QPixmap( (const char**)red_xpm ), "Font color: red",
                              CTRL+Key_R, colors, "redfontcolor", TRUE );

<a name="x2007"></a>    QObject::<a href="qobject.html#connect">connect</a>( colors, SIGNAL( <a href="qactiongroup.html#selected">selected</a>( <a href="qaction.html">QAction</a> * ) ),
                      this, SLOT( setFontColor( <a href="qaction.html">QAction</a> * ) ) );

    <a href="qtoolbar.html">QToolBar</a> * toolbar = new <a href="qtoolbar.html">QToolBar</a>( this, "toolbar" );
<a name="x2006"></a>    colors-&gt;<a href="qactiongroup.html#addTo">addTo</a>( toolbar );

    <a href="qpopupmenu.html">QPopupMenu</a> * font = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
    <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;Font", font );

<a name="x2008"></a>    colors-&gt;<a href="qactiongroup.html#setUsesDropDown">setUsesDropDown</a>( TRUE );
<a name="x2005"></a>    colors-&gt;<a href="qaction.html#setMenuText">setMenuText</a>( "Font Color" );

    colors-&gt;<a href="qactiongroup.html#addTo">addTo</a>( font );

    editor = new <a href="qtextedit.html">QTextEdit</a>( this, "editor" );
    <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( editor );
}


void <a name="f536"></a>Editor::setFontColor( <a href="qaction.html">QAction</a> * coloraction )
{
    if ( coloraction == setRedFont )
<a name="x2010"></a>        editor-&gt;<a href="qtextedit.html#setColor">setColor</a>( red );
    else
        editor-&gt;<a href="qtextedit.html#setColor">setColor</a>( black );
}
</pre>

<p>See also <a href="qaction-examples.html">QAction Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>