You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
695 lines
18 KiB
695 lines
18 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
|
||
|
Copyright (C) 2002 Hamish Rodda <rodda@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
15 years ago
|
#include <tqcursor.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqfontmetrics.h>
|
||
14 years ago
|
|
||
|
#ifdef USE_QT4
|
||
|
#undef None
|
||
|
#endif // USE_QT4
|
||
|
|
||
15 years ago
|
#include <tqstyle.h>
|
||
15 years ago
|
|
||
|
#include "kpopupmenu.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kapplication.h>
|
||
|
|
||
15 years ago
|
KPopupTitle::KPopupTitle(TQWidget *parent, const char *name)
|
||
|
: TQWidget(parent, name)
|
||
15 years ago
|
{
|
||
|
setMinimumSize(16, fontMetrics().height()+8);
|
||
|
}
|
||
|
|
||
|
KPopupTitle::KPopupTitle(KPixmapEffect::GradientType /* gradient */,
|
||
15 years ago
|
const TQColor &/* color */, const TQColor &/* textColor */,
|
||
|
TQWidget *parent, const char *name)
|
||
|
: TQWidget(parent, name)
|
||
15 years ago
|
{
|
||
|
calcSize();
|
||
|
}
|
||
|
|
||
15 years ago
|
KPopupTitle::KPopupTitle(const KPixmap & /* background */, const TQColor &/* color */,
|
||
|
const TQColor &/* textColor */, TQWidget *parent,
|
||
15 years ago
|
const char *name)
|
||
15 years ago
|
: TQWidget(parent, name)
|
||
15 years ago
|
{
|
||
|
calcSize();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupTitle::setTitle(const TQString &text, const TQPixmap *icon)
|
||
15 years ago
|
{
|
||
|
titleStr = text;
|
||
|
if (icon)
|
||
|
miniicon = *icon;
|
||
|
else
|
||
|
miniicon.resize(0, 0);
|
||
|
|
||
|
calcSize();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupTitle::setText( const TQString &text )
|
||
15 years ago
|
{
|
||
|
titleStr = text;
|
||
|
calcSize();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupTitle::setIcon( const TQPixmap &pix )
|
||
15 years ago
|
{
|
||
|
miniicon = pix;
|
||
|
calcSize();
|
||
|
}
|
||
|
|
||
|
void KPopupTitle::calcSize()
|
||
|
{
|
||
15 years ago
|
TQFont f = font();
|
||
15 years ago
|
f.setBold(true);
|
||
15 years ago
|
int w = miniicon.width()+TQFontMetrics(f).width(titleStr);
|
||
15 years ago
|
int h = QMAX( fontMetrics().height(), miniicon.height() );
|
||
|
setMinimumSize( w+16, h+8 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupTitle::paintEvent(TQPaintEvent *)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQRect r(rect());
|
||
|
TQPainter p(this);
|
||
14 years ago
|
kapp->tqstyle().tqdrawPrimitive(TQStyle::PE_HeaderSectionMenu, &p, r, tqpalette().active());
|
||
15 years ago
|
|
||
|
if (!miniicon.isNull())
|
||
|
p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
|
||
|
|
||
|
if (!titleStr.isNull())
|
||
|
{
|
||
14 years ago
|
p.setPen(tqpalette().active().text());
|
||
15 years ago
|
TQFont f = p.font();
|
||
15 years ago
|
f.setBold(true);
|
||
|
p.setFont(f);
|
||
|
if(!miniicon.isNull())
|
||
|
{
|
||
|
p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8),
|
||
|
height(), AlignLeft | AlignVCenter | SingleLine,
|
||
|
titleStr);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
p.drawText(0, 0, width(), height(),
|
||
|
AlignCenter | SingleLine, titleStr);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQSize KPopupTitle::tqsizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqminimumSize();
|
||
15 years ago
|
}
|
||
|
|
||
|
class KPopupMenu::KPopupMenuPrivate
|
||
|
{
|
||
|
public:
|
||
|
KPopupMenuPrivate ()
|
||
|
: noMatches(false)
|
||
|
, shortcuts(false)
|
||
|
, autoExec(false)
|
||
|
, lastHitIndex(-1)
|
||
|
, state(Qt::NoButton)
|
||
|
, m_ctxMenu(0)
|
||
|
{}
|
||
|
|
||
|
~KPopupMenuPrivate ()
|
||
|
{
|
||
|
delete m_ctxMenu;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString m_lastTitle;
|
||
15 years ago
|
|
||
|
// variables for keyboard navigation
|
||
15 years ago
|
TQTimer clearTimer;
|
||
15 years ago
|
|
||
|
bool noMatches : 1;
|
||
|
bool shortcuts : 1;
|
||
|
bool autoExec : 1;
|
||
|
|
||
15 years ago
|
TQString keySeq;
|
||
|
TQString originalText;
|
||
15 years ago
|
|
||
|
int lastHitIndex;
|
||
14 years ago
|
TQt::ButtonState state;
|
||
15 years ago
|
|
||
|
// support for RMB menus on menus
|
||
15 years ago
|
TQPopupMenu* m_ctxMenu;
|
||
15 years ago
|
static bool s_continueCtxMenuShow;
|
||
|
static int s_highlightedItem;
|
||
|
static KPopupMenu* s_contextedMenu;
|
||
|
};
|
||
|
|
||
|
int KPopupMenu::KPopupMenuPrivate::s_highlightedItem(-1);
|
||
|
KPopupMenu* KPopupMenu::KPopupMenuPrivate::s_contextedMenu(0);
|
||
|
bool KPopupMenu::KPopupMenuPrivate::s_continueCtxMenuShow(true);
|
||
|
|
||
15 years ago
|
KPopupMenu::KPopupMenu(TQWidget *parent, const char *name)
|
||
|
: TQPopupMenu(parent, name)
|
||
15 years ago
|
{
|
||
|
d = new KPopupMenuPrivate;
|
||
|
resetKeyboardVars();
|
||
15 years ago
|
connect(&(d->clearTimer), TQT_SIGNAL(timeout()), TQT_SLOT(resetKeyboardVars()));
|
||
15 years ago
|
}
|
||
|
|
||
|
KPopupMenu::~KPopupMenu()
|
||
|
{
|
||
|
if (KPopupMenuPrivate::s_contextedMenu == this)
|
||
|
{
|
||
|
KPopupMenuPrivate::s_contextedMenu = 0;
|
||
|
KPopupMenuPrivate::s_highlightedItem = -1;
|
||
|
}
|
||
|
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KPopupMenu::insertTitle(const TQString &text, int id, int index)
|
||
15 years ago
|
{
|
||
|
KPopupTitle *titleItem = new KPopupTitle();
|
||
|
titleItem->setTitle(text);
|
||
|
int ret = insertItem(titleItem, id, index);
|
||
|
setItemEnabled(ret, false);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KPopupMenu::insertTitle(const TQPixmap &icon, const TQString &text, int id,
|
||
15 years ago
|
int index)
|
||
|
{
|
||
|
KPopupTitle *titleItem = new KPopupTitle();
|
||
|
titleItem->setTitle(text, &icon);
|
||
|
int ret = insertItem(titleItem, id, index);
|
||
|
setItemEnabled(ret, false);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::changeTitle(int id, const TQString &text)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQMenuItem *item = findItem(id);
|
||
15 years ago
|
if(item){
|
||
|
if(item->widget())
|
||
|
((KPopupTitle *)item->widget())->setTitle(text);
|
||
|
#ifndef NDEBUG
|
||
|
else
|
||
|
kdWarning() << "KPopupMenu: changeTitle() called with non-title id "<< id << endl;
|
||
|
#endif
|
||
|
}
|
||
|
#ifndef NDEBUG
|
||
|
else
|
||
|
kdWarning() << "KPopupMenu: changeTitle() called with invalid id " << id << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::changeTitle(int id, const TQPixmap &icon, const TQString &text)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQMenuItem *item = findItem(id);
|
||
15 years ago
|
if(item){
|
||
|
if(item->widget())
|
||
|
((KPopupTitle *)item->widget())->setTitle(text, &icon);
|
||
|
#ifndef NDEBUG
|
||
|
else
|
||
|
kdWarning() << "KPopupMenu: changeTitle() called with non-title id "<< id << endl;
|
||
|
#endif
|
||
|
}
|
||
|
#ifndef NDEBUG
|
||
|
else
|
||
|
kdWarning() << "KPopupMenu: changeTitle() called with invalid id " << id << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KPopupMenu::title(int id) const
|
||
15 years ago
|
{
|
||
|
if(id == -1) // obsolete
|
||
|
return d->m_lastTitle;
|
||
13 years ago
|
TQMenuItem *item = findItem(id);
|
||
15 years ago
|
if(item){
|
||
|
if(item->widget())
|
||
|
return ((KPopupTitle *)item->widget())->title();
|
||
|
else
|
||
|
qWarning("KPopupMenu: title() called with non-title id %d.", id);
|
||
|
}
|
||
|
else
|
||
|
qWarning("KPopupMenu: title() called with invalid id %d.", id);
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQPixmap KPopupMenu::titlePixmap(int id) const
|
||
15 years ago
|
{
|
||
13 years ago
|
TQMenuItem *item = findItem(id);
|
||
15 years ago
|
if(item){
|
||
|
if(item->widget())
|
||
|
return ((KPopupTitle *)item->widget())->icon();
|
||
|
else
|
||
|
qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id);
|
||
|
}
|
||
|
else
|
||
|
qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id);
|
||
15 years ago
|
TQPixmap tmp;
|
||
15 years ago
|
return tmp;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* This is re-implemented for keyboard navigation.
|
||
|
*/
|
||
15 years ago
|
void KPopupMenu::closeEvent(TQCloseEvent*e)
|
||
15 years ago
|
{
|
||
|
if (d->shortcuts)
|
||
|
resetKeyboardVars();
|
||
15 years ago
|
TQPopupMenu::closeEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KPopupMenu::activateItemAt(int index)
|
||
|
{
|
||
|
d->state = Qt::NoButton;
|
||
15 years ago
|
TQPopupMenu::activateItemAt(index);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQt::ButtonState KPopupMenu::state() const
|
||
15 years ago
|
{
|
||
|
return d->state;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::keyPressEvent(TQKeyEvent* e)
|
||
15 years ago
|
{
|
||
|
d->state = Qt::NoButton;
|
||
|
if (!d->shortcuts) {
|
||
|
// continue event processing by Qpopup
|
||
|
//e->ignore();
|
||
|
d->state = e->state();
|
||
15 years ago
|
TQPopupMenu::keyPressEvent(e);
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
int i = 0;
|
||
|
bool firstpass = true;
|
||
15 years ago
|
TQString keyString = e->text();
|
||
15 years ago
|
|
||
|
// check for common commands dealt with by QPopup
|
||
|
int key = e->key();
|
||
|
if (key == Key_Escape || key == Key_Return || key == Key_Enter
|
||
|
|| key == Key_Up || key == Key_Down || key == Key_Left
|
||
|
|| key == Key_Right || key == Key_F1) {
|
||
|
|
||
|
resetKeyboardVars();
|
||
|
// continue event processing by Qpopup
|
||
|
//e->ignore();
|
||
|
d->state = e->state();
|
||
15 years ago
|
TQPopupMenu::keyPressEvent(e);
|
||
15 years ago
|
return;
|
||
|
} else if ( key == Key_Shift || key == Key_Control || key == Key_Alt || key == Key_Meta )
|
||
15 years ago
|
return TQPopupMenu::keyPressEvent(e);
|
||
15 years ago
|
|
||
|
// check to see if the user wants to remove a key from the sequence (backspace)
|
||
|
// or clear the sequence (delete)
|
||
|
if (!d->keySeq.isNull()) {
|
||
|
|
||
|
if (key == Key_Backspace) {
|
||
|
|
||
|
if (d->keySeq.length() == 1) {
|
||
|
resetKeyboardVars();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// keep the last sequence in keyString
|
||
|
keyString = d->keySeq.left(d->keySeq.length() - 1);
|
||
|
|
||
|
// allow sequence matching to be tried again
|
||
|
resetKeyboardVars();
|
||
|
|
||
|
} else if (key == Key_Delete) {
|
||
|
resetKeyboardVars();
|
||
|
|
||
|
// clear active item
|
||
|
setActiveItem(0);
|
||
|
return;
|
||
|
|
||
|
} else if (d->noMatches) {
|
||
|
// clear if there are no matches
|
||
|
resetKeyboardVars();
|
||
|
|
||
|
// clear active item
|
||
|
setActiveItem(0);
|
||
|
|
||
|
} else {
|
||
|
// the key sequence is not a null string
|
||
|
// therefore the lastHitIndex is valid
|
||
|
i = d->lastHitIndex;
|
||
|
}
|
||
14 years ago
|
} else if (key == Key_Backspace && parentMenu) {
|
||
15 years ago
|
// backspace with no chars in the buffer... go back a menu.
|
||
|
hide();
|
||
|
resetKeyboardVars();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
d->keySeq += keyString;
|
||
|
int seqLen = d->keySeq.length();
|
||
|
|
||
|
for (; i < (int)count(); i++) {
|
||
|
// compare typed text with text of this entry
|
||
|
int j = idAt(i);
|
||
|
|
||
|
// don't search disabled entries
|
||
|
if (!isItemEnabled(j))
|
||
|
continue;
|
||
|
|
||
15 years ago
|
TQString thisText;
|
||
15 years ago
|
|
||
|
// retrieve the right text
|
||
|
// (the last selected item one may have additional ampersands)
|
||
|
if (i == d->lastHitIndex)
|
||
|
thisText = d->originalText;
|
||
|
else
|
||
|
thisText = text(j);
|
||
|
|
||
|
// if there is an accelerator present, remove it
|
||
|
if ((int)accel(j) != 0)
|
||
13 years ago
|
thisText = thisText.replace("&", TQString());
|
||
15 years ago
|
|
||
|
// chop text to the search length
|
||
|
thisText = thisText.left(seqLen);
|
||
|
|
||
|
// do the search
|
||
13 years ago
|
if (!thisText.find(d->keySeq, 0, false)) {
|
||
15 years ago
|
|
||
|
if (firstpass) {
|
||
|
// match
|
||
|
setActiveItem(i);
|
||
|
|
||
|
// check to see if we're underlining a different item
|
||
|
if (d->lastHitIndex != i)
|
||
|
// yes; revert the underlining
|
||
|
changeItem(idAt(d->lastHitIndex), d->originalText);
|
||
|
|
||
|
// set the original text if it's a different item
|
||
|
if (d->lastHitIndex != i || d->lastHitIndex == -1)
|
||
|
d->originalText = text(j);
|
||
|
|
||
|
// underline the currently selected item
|
||
|
changeItem(j, underlineText(d->originalText, d->keySeq.length()));
|
||
|
|
||
|
// remember what's going on
|
||
|
d->lastHitIndex = i;
|
||
|
|
||
|
// start/restart the clear timer
|
||
|
d->clearTimer.start(5000, true);
|
||
|
|
||
|
// go around for another try, to see if we can execute
|
||
|
firstpass = false;
|
||
|
} else {
|
||
|
// don't allow execution
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// fall through to allow execution
|
||
|
}
|
||
|
|
||
|
if (!firstpass) {
|
||
|
if (d->autoExec) {
|
||
|
// activate anything
|
||
|
activateItemAt(d->lastHitIndex);
|
||
|
resetKeyboardVars();
|
||
|
|
||
13 years ago
|
} else if (findItem(idAt(d->lastHitIndex)) &&
|
||
|
findItem(idAt(d->lastHitIndex))->popup()) {
|
||
15 years ago
|
// only activate sub-menus
|
||
|
activateItemAt(d->lastHitIndex);
|
||
|
resetKeyboardVars();
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// no matches whatsoever, clean up
|
||
|
resetKeyboardVars(true);
|
||
|
//e->ignore();
|
||
15 years ago
|
TQPopupMenu::keyPressEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
|
bool KPopupMenu::focusNextPrevChild( bool next )
|
||
|
{
|
||
|
resetKeyboardVars();
|
||
15 years ago
|
return TQPopupMenu::focusNextPrevChild( next );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString KPopupMenu::underlineText(const TQString& text, uint length)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString ret = text;
|
||
15 years ago
|
for (uint i = 0; i < length; i++) {
|
||
|
if (ret[2*i] != '&')
|
||
|
ret.insert(2*i, "&");
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::resetKeyboardVars(bool noMatches /* = false */)
|
||
|
{
|
||
|
// Clean up keyboard variables
|
||
|
if (d->lastHitIndex != -1) {
|
||
|
changeItem(idAt(d->lastHitIndex), d->originalText);
|
||
|
d->lastHitIndex = -1;
|
||
|
}
|
||
|
|
||
|
if (!noMatches) {
|
||
15 years ago
|
d->keySeq = TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
d->noMatches = noMatches;
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::setKeyboardShortcutsEnabled(bool enable)
|
||
|
{
|
||
|
d->shortcuts = enable;
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::setKeyboardShortcutsExecute(bool enable)
|
||
|
{
|
||
|
d->autoExec = enable;
|
||
|
}
|
||
|
/**
|
||
|
* End keyboard navigation.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* RMB menus on menus
|
||
|
*/
|
||
|
|
||
15 years ago
|
void KPopupMenu::mousePressEvent(TQMouseEvent* e)
|
||
15 years ago
|
{
|
||
|
if (d->m_ctxMenu && d->m_ctxMenu->isVisible())
|
||
|
{
|
||
|
// hide on a second context menu event
|
||
|
d->m_ctxMenu->hide();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu::mousePressEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::mouseReleaseEvent(TQMouseEvent* e)
|
||
15 years ago
|
{
|
||
|
// Save the button, and the modifiers from state()
|
||
14 years ago
|
d->state = TQt::ButtonState(e->button() | (e->state() & KeyButtonMask));
|
||
15 years ago
|
|
||
|
if ( !d->m_ctxMenu || !d->m_ctxMenu->isVisible() )
|
||
15 years ago
|
TQPopupMenu::mouseReleaseEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu* KPopupMenu::contextMenu()
|
||
15 years ago
|
{
|
||
|
if (!d->m_ctxMenu)
|
||
|
{
|
||
15 years ago
|
d->m_ctxMenu = new TQPopupMenu(this);
|
||
|
connect(d->m_ctxMenu, TQT_SIGNAL(aboutToHide()), this, TQT_SLOT(ctxMenuHiding()));
|
||
15 years ago
|
}
|
||
|
|
||
|
return d->m_ctxMenu;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQPopupMenu* KPopupMenu::contextMenu() const
|
||
15 years ago
|
{
|
||
|
return const_cast< KPopupMenu* >( this )->contextMenu();
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::hideContextMenu()
|
||
|
{
|
||
|
KPopupMenuPrivate::s_continueCtxMenuShow = false;
|
||
|
}
|
||
|
|
||
|
int KPopupMenu::contextMenuFocusItem()
|
||
|
{
|
||
|
return KPopupMenuPrivate::s_highlightedItem;
|
||
|
}
|
||
|
|
||
|
KPopupMenu* KPopupMenu::contextMenuFocus()
|
||
|
{
|
||
|
return KPopupMenuPrivate::s_contextedMenu;
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::itemHighlighted(int /* whichItem */)
|
||
|
{
|
||
|
if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible())
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
d->m_ctxMenu->hide();
|
||
15 years ago
|
showCtxMenu(mapFromGlobal(TQCursor::pos()));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::showCtxMenu(TQPoint pos)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQMenuItem* item = findItem(KPopupMenuPrivate::s_highlightedItem);
|
||
15 years ago
|
if (item)
|
||
|
{
|
||
15 years ago
|
TQPopupMenu* subMenu = item->popup();
|
||
15 years ago
|
if (subMenu)
|
||
|
{
|
||
15 years ago
|
disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
KPopupMenuPrivate::s_highlightedItem = idAt(pos);
|
||
|
|
||
|
if (KPopupMenuPrivate::s_highlightedItem == -1)
|
||
|
{
|
||
|
KPopupMenuPrivate::s_contextedMenu = 0;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
emit aboutToShowContextMenu(this, KPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu);
|
||
|
|
||
13 years ago
|
TQPopupMenu* subMenu = findItem(KPopupMenuPrivate::s_highlightedItem)->popup();
|
||
15 years ago
|
if (subMenu)
|
||
|
{
|
||
15 years ago
|
connect(subMenu, TQT_SIGNAL(aboutToShow()), TQT_SLOT(ctxMenuHideShowingMenu()));
|
||
|
TQTimer::singleShot(100, subMenu, TQT_SLOT(hide()));
|
||
15 years ago
|
}
|
||
|
|
||
|
if (!KPopupMenuPrivate::s_continueCtxMenuShow)
|
||
|
{
|
||
|
KPopupMenuPrivate::s_continueCtxMenuShow = true;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
KPopupMenuPrivate::s_contextedMenu = this;
|
||
|
d->m_ctxMenu->popup(this->mapToGlobal(pos));
|
||
15 years ago
|
connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int)));
|
||
15 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* this method helps prevent submenus popping up while we have a context menu
|
||
|
* showing
|
||
|
*/
|
||
|
void KPopupMenu::ctxMenuHideShowingMenu()
|
||
|
{
|
||
13 years ago
|
TQMenuItem* item = findItem(KPopupMenuPrivate::s_highlightedItem);
|
||
15 years ago
|
if (item)
|
||
|
{
|
||
15 years ago
|
TQPopupMenu* subMenu = item->popup();
|
||
15 years ago
|
if (subMenu)
|
||
|
{
|
||
15 years ago
|
TQTimer::singleShot(0, subMenu, TQT_SLOT(hide()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KPopupMenu::ctxMenuHiding()
|
||
|
{
|
||
|
if (KPopupMenuPrivate::s_highlightedItem)
|
||
|
{
|
||
13 years ago
|
TQPopupMenu* subMenu = findItem(KPopupMenuPrivate::s_highlightedItem)->popup();
|
||
15 years ago
|
if (subMenu)
|
||
|
{
|
||
15 years ago
|
disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
disconnect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int)));
|
||
15 years ago
|
KPopupMenuPrivate::s_continueCtxMenuShow = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::contextMenuEvent(TQContextMenuEvent* e)
|
||
15 years ago
|
{
|
||
|
if (d->m_ctxMenu)
|
||
|
{
|
||
15 years ago
|
if (e->reason() == TQContextMenuEvent::Mouse)
|
||
15 years ago
|
{
|
||
|
showCtxMenu(e->pos());
|
||
|
}
|
||
|
else if (actItem != -1)
|
||
|
{
|
||
|
showCtxMenu(itemGeometry(actItem).center());
|
||
|
}
|
||
|
|
||
|
e->accept();
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu::contextMenuEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KPopupMenu::hideEvent(TQHideEvent*)
|
||
15 years ago
|
{
|
||
|
if (d->m_ctxMenu && d->m_ctxMenu->isVisible())
|
||
|
{
|
||
|
// we need to block signals here when the ctxMenu is showing
|
||
15 years ago
|
// to prevent the TQPopupMenu::activated(int) signal from emitting
|
||
15 years ago
|
// when hiding with a context menu, the user doesn't expect the
|
||
|
// menu to actually do anything.
|
||
|
// since hideEvent gets called very late in the process of hiding
|
||
15 years ago
|
// (deep within TQWidget::hide) the activated(int) signal is the
|
||
15 years ago
|
// last signal to be emitted, even after things like aboutToHide()
|
||
|
// AJS
|
||
|
blockSignals(true);
|
||
|
d->m_ctxMenu->hide();
|
||
|
blockSignals(false);
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* end of RMB menus on menus support
|
||
|
*/
|
||
|
|
||
|
// Obsolete
|
||
15 years ago
|
KPopupMenu::KPopupMenu(const TQString& title, TQWidget *parent, const char *name)
|
||
|
: TQPopupMenu(parent, name)
|
||
15 years ago
|
{
|
||
|
d = new KPopupMenuPrivate;
|
||
|
insertTitle(title);
|
||
|
}
|
||
|
|
||
|
// Obsolete
|
||
15 years ago
|
void KPopupMenu::setTitle(const TQString &title)
|
||
15 years ago
|
{
|
||
|
KPopupTitle *titleItem = new KPopupTitle();
|
||
|
titleItem->setTitle(title);
|
||
|
insertItem(titleItem);
|
||
|
d->m_lastTitle = title;
|
||
|
}
|
||
|
|
||
|
void KPopupTitle::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
void KPopupMenu::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
#include "kpopupmenu.moc"
|