Ran qt3to4
[basket4.git] / src / popupmenu.h
blob654332e11bb3e21e2a1e37a7614c2b3c969de3cf
1 //Added by qt3to4:
2 #include <Q3PopupMenu>
3 /***************************************************************************
4 * Copyright (C) 2003 by Sébastien Laoût *
5 * slaout@linux62.org *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
23 #ifndef POPUPMENU_H
24 #define POPUPMENU_H
26 class Q3PopupMenu;
27 class QRect;
29 /** QPopupMenu/KPopupMenu doesn't provide metod to exec a menu
30 * at a given rectangle !
31 * eg, popup at bottom of a rectangle, and at top if not possible...
32 * @author Sébastien Laoût
34 namespace PopupMenu
36 /** Show the popup menu centered into rect.
38 void execAtRectCenter(Q3PopupMenu &menu, const QRect &rect);
40 /** Show the popup menu at left-bottom of rect, or at right-bottom
41 * if not possible (not enought place).
42 * If it isn't possible to show it at bottom, it will be shown on
43 * top of rect (top-left if possible, if not it will be top-right).
44 * If center is true, it will try to horizontaly center the popup with
45 * rect, so it will try two positions : bottom center and then top center.
47 void execAtRectBottom(Q3PopupMenu &menu, const QRect &rect, bool centered = false);
49 /** Idem execAtRectBottom but on the right or left sides,
50 * prior aligned with the top of the rect, and at the bottom
51 * if not possible.
52 * If center is true, it will try to vertically center the popup with
53 * rect, so it will try two positions : right center and then left center.
55 void execAtRectRight(Q3PopupMenu &menu, const QRect &rect, bool centered = false);
58 /** Test window of PopupMenu methods.
59 * Just include popupmenu.h in a main Qt application and call
60 * new PopupMenuTest();
61 * Click the window for more explications.
62 * Resize it to test particular cases.
63 * (Comment the class, if it isn't done yet to do not compile it :-) ).
64 * @author Sébastien Laoût
67 /*****
69 #include <qwidget.h>
70 #include <qpopupmenu.h>
71 #include <qpainter.h>
72 #include <qpen.h>
74 c l a s s P o p u p M e n u T e s t : p u b l i c Q W i d g e t
76 Q _ O B J E C T
77 p u b l i c:
78 PopupMenuTest()
79 : QWidget(0)
81 setCaption("Click to test!");
82 show();
85 void mousePressEvent(QMouseEvent *event)
87 QPopupMenu menu;
88 QRect rect( mapToGlobal(QPoint(0,0)), size() );
90 menu.insertItem("A test of popup menu!");
91 menu.insertItem("This menu contain some items");
92 menu.insertItem("Resize the window as you want and:");
93 menu.insertItem("- click : execAtRectCenter");
94 menu.insertItem("- right click : execAtRectBottom");
95 menu.insertItem("- middle click : execAtRectRight");
96 menu.insertItem("- Shift + right click : execAtRectBottom centered");
97 menu.insertItem("- Shift + middle click : execAtRectRight centered");
99 if (event->button() & Qt::LeftButton)
100 PopupMenu::execAtRectCenter(menu, rect);
101 else if ((event->button() & Qt::RightButton) && (event->state() & Qt::ShiftButton))
102 PopupMenu::execAtRectBottom(menu, rect, true);
103 else if (event->button() & Qt::RightButton)
104 PopupMenu::execAtRectBottom(menu, rect);
105 else if ((event->button() & Qt::MidButton) && (event->state() & Qt::ShiftButton))
106 PopupMenu::execAtRectRight(menu, rect, true);
107 else if (event->button() & Qt::MidButton)
108 PopupMenu::execAtRectRight(menu, rect);
111 void paintEvent(QPaintEvent*)
113 QPainter paint(this);
114 paint.setPen(paletteBackgroundColor());
115 paint.drawRect(rect());
116 paint.drawWinFocusRect(rect());
117 paint.setPen( QPen(Qt::black, 1) );
118 paint.drawLine( rect().topLeft(), rect().bottomRight() );
119 paint.drawLine( rect().topRight(), rect().bottomLeft() );
123 *****/
125 #endif // POPUPMENU_H