void ossimQtSingleImageWindow::exportImage()
{
    if (!theImageChain.valid())
    {
        QString caption = "Sorry:";
        QString text = "You must open an image first.";
        text += "  Use \"File->Open Image\"\n";
        QMessageBox::information( this,
                                  caption,
                                  text,
                                  QMessageBox::Ok );
        return;
    }

    ossimString name = "ossimQtIcpDialog";

    // First see if we already have a dialog open for this.
    QWidget* w = ossimQtEditorWidgetManager::instance()->getFromList(name,
                 this);
    if (w)
    {
        w->raise();
        return;
    }

    w = new ossimQtIcpDialog(this, theImageChain.get());

    // Add to the list so we don't make a duplicate dialog.
    ossimQtEditorWidgetManager::instance()->addToList(w, this);

    w->show();
}
void
bringToFront()
{
#if defined(Q_WS_X11)
    {
        qDebug() << Q_FUNC_INFO;

        QWidget* widget = tomahawkWindow();
        if ( !widget )
            return;

        widget->show();
        widget->activateWindow();
        widget->raise();

        WId wid = widget->winId();
        NETWM::init();

        XEvent e;
        e.xclient.type = ClientMessage;
        e.xclient.message_type = NETWM::NET_ACTIVE_WINDOW;
        e.xclient.display = QX11Info::display();
        e.xclient.window = wid;
        e.xclient.format = 32;
        e.xclient.data.l[0] = 2;
        e.xclient.data.l[1] = QX11Info::appTime();
        e.xclient.data.l[2] = 0;
        e.xclient.data.l[3] = 0l;
        e.xclient.data.l[4] = 0l;

        XSendEvent( QX11Info::display(), RootWindow( QX11Info::display(), DefaultScreen( QX11Info::display() ) ), False, SubstructureRedirectMask | SubstructureNotifyMask, &e );
    }
#elif defined(Q_WS_WIN)
    {
        qDebug() << Q_FUNC_INFO;

        QWidget* widget = tomahawkWindow();
        if ( !widget )
            return;

        widget->show();
        widget->activateWindow();
        widget->raise();

        WId wid = widget->winId();

        HWND hwndActiveWin = GetForegroundWindow();
        int  idActive      = GetWindowThreadProcessId(hwndActiveWin, NULL);
        if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
        {
            SetForegroundWindow( wid );
            SetFocus( wid );
            AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
        }
    }
#endif
}
Example #3
0
void KSystemTray::minimizeRestore(bool restore)
{
    QWidget *pw = parentWidget();
    if(!pw)
        return;
#ifdef Q_WS_X11
    KWin::WindowInfo info = KWin::windowInfo(pw->winId(), NET::WMGeometry | NET::WMDesktop);
    if(restore)
    {
        if(d->on_all_desktops)
            KWin::setOnAllDesktops(pw->winId(), true);
        else
            KWin::setCurrentDesktop(info.desktop());
        pw->move(info.geometry().topLeft()); // avoid placement policies
        pw->show();
        pw->raise();
        KWin::activateWindow(pw->winId());
    }
    else
    {
        d->on_all_desktops = info.onAllDesktops();
        pw->hide();
    }
#endif
}
Example #4
0
void QWidgetPrivate::raise_sys()
{
    Q_Q(QWidget);
    //@@@ transaction
    if (q->isWindow()) {
        Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
        QWidget::qwsDisplay()->setAltitude(q->internalWinId(),
                                           QWSChangeAltitudeCommand::Raise);
        // XXX: subsurfaces?
#ifdef QT_NO_WINDOWGROUPHINT
#else
        QObjectList childObjects =  q->children();
        if (!childObjects.isEmpty()) {
            QWidgetList toraise;
            for (int i = 0; i < childObjects.size(); ++i) {
                QObject *obj = childObjects.at(i);
                if (obj->isWidgetType()) {
                    QWidget* w = static_cast<QWidget*>(obj);
                    if (w->isWindow())
                        toraise.append(w);
                }
            }

            for (int i = 0; i < toraise.size(); ++i) {
                QWidget *w = toraise.at(i);
                if (w->isVisible())
                    w->raise();
            }
        }
#endif // QT_NO_WINDOWGROUPHINT
    }
}
Example #5
0
void bringToFront(QWidget *widget, bool)
{
	Q_ASSERT(widget);
	QWidget* w = widget->window();

#ifdef Q_WS_X11
	// If we're not on the current desktop, do the hide/show trick
	long dsk, curr_dsk;
	Window win = w->winId();
	if(desktopOfWindow(&win, &dsk) && currentDesktop(&curr_dsk)) {
		if((dsk != curr_dsk) && (dsk != -1)) {  // second condition for sticky windows
			w->hide();
		}
	}

	// FIXME: multi-desktop hacks for Win and Mac required
#endif

	if(w->isMaximized())
		w->showMaximized();
	else
		w->showNormal();

	//if(grabFocus)
	//	w->setActiveWindow();
	w->raise();
	w->activateWindow();

#ifdef Q_WS_WIN
	// TODO: unify with AdvancedWidget::bringToFront()
	ForceForegroundWindow(w->winId());
#endif
}
Example #6
0
void QgsCredentialDialog::requestCredentials( const QString& realm, QString *username, QString *password, const QString& message, bool *ok )
{
  Q_ASSERT( qApp->thread() == thread() && thread() == QThread::currentThread() );
  QgsDebugMsg( "Entering." );
  stackedWidget->setCurrentIndex( 0 );

  labelRealm->setText( realm );
  leUsername->setText( *username );
  lePassword->setText( *password );
  labelMessage->setText( message );
  labelMessage->setHidden( message.isEmpty() );

  if ( !leUsername->text().isEmpty() )
    lePassword->setFocus();

  QWidget *activeWindow = qApp->activeWindow();

  QApplication::setOverrideCursor( Qt::ArrowCursor );

  QgsDebugMsg( "exec()" );
  *ok = exec() == QDialog::Accepted;
  QgsDebugMsg( QString( "exec(): %1" ).arg( *ok ? "true" : "false" ) );

  QApplication::restoreOverrideCursor();

  if ( activeWindow )
    activeWindow->raise();

  if ( *ok )
  {
    *username = leUsername->text();
    *password = lePassword->text();
  }
}
Example #7
0
bool qt_try_modal(QWidget *widget, QEvent::Type type)
{
    QWidget * top = 0;

    if (QApplicationPrivate::tryModalHelper(widget, &top))
        return true;

    bool block_event  = false;
    bool paint_event = false;

    switch (type) {
#if 0
    case QEvent::Focus:
        if (!static_cast<QWSFocusEvent*>(event)->simpleData.get_focus)
            break;
        // drop through
#endif
    case QEvent::MouseButtonPress:                        // disallow mouse/key events
    case QEvent::MouseButtonRelease:
    case QEvent::MouseMove:
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
        block_event         = true;
        break;
    default:
        break;
    }

    if ((block_event || paint_event) && top->parentWidget() == 0)
        top->raise();

    return !block_event;
}
Example #8
0
/*!
    \property QStackedLayout::currentIndex
    \brief the index position of the widget that is visible

    The current index is -1 if there is no current widget.

    \sa currentWidget(), indexOf()
*/
void QStackedLayout::setCurrentIndex(int index)
{
    Q_D(QStackedLayout);
    QWidget *prev = currentWidget();
    QWidget *next = widget(index);
    if (!next || next == prev)
        return;

    bool reenableUpdates = false;
    QWidget *parent = parentWidget();

    if (parent && parent->updatesEnabled()) {
        reenableUpdates = true;
        parent->setUpdatesEnabled(false);
    }

    QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0;
    const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw));

    if (prev) {
        prev->clearFocus();
        if (d->stackingMode == StackOne)
            prev->hide();
    }

    d->index = index;
    next->raise();
    next->show();

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.

    if (parent) {
        if (focusWasOnOldPage) {
            // look for the best focus widget we can find
            if (QWidget *nfw = next->focusWidget())
                nfw->setFocus();
            else {
                // second best: first child widget in the focus chain
                if (QWidget *i = fw) {
                    while ((i = i->nextInFocusChain()) != fw) {
                        if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                            && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
                            && next->isAncestorOf(i)) {
                            i->setFocus();
                            break;
                        }
                    }
                    // third best: incoming widget
                    if (i == fw )
                        next->setFocus();
                }
            }
        }
    }
    if (reenableUpdates)
        parent->setUpdatesEnabled(true);
    emit currentChanged(index);
}
Example #9
0
void MainWindow::configureFilter() {
  QWidget *widget = filter.settings();
  if(widget) {
    widget->show();
    widget->activateWindow();
    widget->raise();
  }
}
Example #10
0
int main(int argc, char** argv)
{
  QApplication app(argc, argv);
  QWidget w;
  w.setWindowTitle("Test Dummy Application");
  w.show();
  w.raise();
  return app.exec();
}
void ConnectionPageWindowObject::showAndActivate()
{
    QWidget *widget = dynamic_cast<QWidget*>(this);
    Q_ASSERT(widget);

    widget->show();
    widget->activateWindow();
    widget->raise();
}
Example #12
0
bool QWidgetProxy::bringFront() {
  QWidget *w = widget();
  if( !w ) return true;
  w->setWindowState( w->windowState() & ~Qt::WindowMinimized
                                      | Qt::WindowActive );
  w->show();
  w->raise();

  return true;
}
PlaylistBrowser::PlaylistBrowser(QWidget *parent) :
    QWidget(parent)
{
    p = new PlaylistBrowsertPrivate;

    QPushButton* pushSave =new QPushButton();
    pushSave->setGeometry(QRect(1,1,60,25));
    pushSave->setMaximumWidth(60);
    pushSave->setMinimumWidth(60);
    pushSave->setText("+");
    QFont pushFont = pushSave->font();
    pushFont.setBold(true);
    pushFont.setPointSize(pushFont.pointSize()+4);
    pushSave->setFont(pushFont);

    pushSave->setStyleSheet("QPushButton { border: none; padding-top: -3px; margin-left: 8px;max-height: 20px; margin-right: 28px;}");
    pushSave->setToolTip(tr( "Add a new list and store current tracks" ));
    connect( pushSave,SIGNAL(clicked()),this, SLOT(onPushSave()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    QWidget *headWidget = new QWidget(this);
    headWidget->setMaximumHeight(35);
    headWidget->setMinimumHeight(25);

    QHBoxLayout *headWidgetLayout = new QHBoxLayout;
    headWidgetLayout->setMargin(0);
    headWidgetLayout->setSpacing(1);
    headWidgetLayout->setAlignment(Qt::AlignRight);

    headWidgetLayout->addWidget(pushSave);
    headWidget->setLayout(headWidgetLayout);

    p->listPlaylists = new QListWidget();
    p->listPlaylists->setAttribute(Qt::WA_MacShowFocusRect, false);

    p->database  = new CollectionDB();
    p->database->executeSql( "PRAGMA synchronous = OFF;" );

    updateLists();

    headWidget->raise();
    mainLayout->addWidget(headWidget);
    mainLayout->addWidget(p->listPlaylists);

    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    setMaximumWidth(400);

    p->directory = "";

    setLayout(mainLayout);

}
Example #14
0
void IndicatorService::showMainWindow()
{
	qutim_sdk_0_3::debug() << "showMainWindow";
	if (QObject *obj = qutim_sdk_0_3::ServiceManager::getByName("ContactList"))
	{
		QMetaObject::invokeMethod(obj, "show");
		QWidget *objWidget = qobject_cast<QWidget*>(obj);
		if (objWidget)
			objWidget->raise();
	}
}
Example #15
0
void MainWindow::snapshot(QPixmap &pm)
{
  if(opt.arg_debug) printf("snapshot\n");
  QWidget *w = centralWidget();
  if(w != NULL)
  {
    w->raise();
    //pm = QPixmap::grabWindow(w->winId(),0,0,w->width(),w->height());
    pm = QPixmap::grabWidget(w,0,0,w->width(),w->height());
  }  
  if(opt.arg_debug) printf("snapshot done\n");
}
Example #16
0
void ICore::raiseWindow(QWidget *widget)
{
    if (!widget)
        return;
    QWidget *window = widget->window();
    if (window == m_mainwindow) {
        m_mainwindow->raiseWindow();
    } else {
        window->raise();
        window->activateWindow();
    }
}
Example #17
0
void toPieChart::openCopy(void)
{
    QWidget *newWin = new toPieChart(this,
                                     toMainWidget()->workspace(),
                                     NULL,
                                     0);

    newWin->setAttribute(Qt::WA_DeleteOnClose);
    newWin->show();
    newWin->raise();
    newWin->setFocus();
    toMainWidget()->updateWindowsMenu();
}
Example #18
0
void QWidget::raise()
{
    QWidget *p = parentWidget();
    if ( p && p->childObjects && p->childObjects->findRef(this) >= 0 )
	p->childObjects->append( p->childObjects->take() );
    if ( isTopLevel() ) {
#ifdef QT_NO_WINDOWGROUPHINT
	if ( !testWFlags( WStyle_Tool ) )
	    setActiveWindow();
	qwsDisplay()->setAltitude( winId(), 0 );
#else
	QWidget* act=0;
	if ( !testWFlags( WStyle_Tool ) )
	    act=this;
	qwsDisplay()->setAltitude( winId(), 0 );
	if ( childObjects ) {
	    QObjectListIt it(*childObjects);
	    QObject* o;
	    QWidgetList toraise;
	    QWidget* w;
	    while ((o=it.current())) {
		if ( o->isWidgetType() ) {
		    w = (QWidget*)o;
		    if ( w->isTopLevel() )
			toraise.append(w);
		}
		++it;
	    }
	    QWidgetListIt wit(toraise);
	    while ((w=wit.current())) {
		if ( w->isVisible() ) {
		    bool wastool = w->testWFlags( WStyle_Tool );
		    w->setWFlags( WStyle_Tool ); // avoid setActiveWindow flicker
		    w->raise();
		    if ( !wastool ) {
			w->clearWFlags( WStyle_Tool );
			act = w;
		    }
		}
		++wit;
	    }
	}
	if ( act )
	    act->setActiveWindow();
#endif // QT_NO_WINDOWGROUPHINT
    } else if ( p ) {
	p->setChildrenAllocatedDirty( geometry(), this );
	paint_heirarchy( this, TRUE );
    }
}
Example #19
0
void InputManager::createAndShow(QWidget* parent, InputMap* inputMap)
{
    QWidget* window = NULL;

    /* Must not create more than one instance */
    if (s_instance == NULL)
    {
#ifdef __APPLE__
        /* Create a separate window for OSX */
        s_instance = new InputManager(parent, inputMap, Qt::Window);
        window = s_instance;
#else
        /* Create an MDI window for X11 & Win32 */
        QMdiArea* area = qobject_cast<QMdiArea*> (parent);
        Q_ASSERT(area != NULL);
        QMdiSubWindow* sub = new QMdiSubWindow;
        s_instance = new InputManager(sub, inputMap);
        sub->setWidget(s_instance);
        window = area->addSubWindow(sub);
#endif

        /* Set some common properties for the window and show it */
        window->setAttribute(Qt::WA_DeleteOnClose);
        window->setWindowIcon(QIcon(":/input.png"));
        window->setWindowTitle(tr("Input Manager"));
        window->setContextMenuPolicy(Qt::CustomContextMenu);
        window->show();

        QSettings settings;
        QVariant var = settings.value(SETTINGS_GEOMETRY);
        if (var.isValid() == true)
        {
            window->restoreGeometry(var.toByteArray());
            AppUtil::ensureWidgetIsVisible(window);
        }
    }
    else
    {
#ifdef __APPLE__
        window = s_instance;
#else
        window = s_instance->parentWidget();
#endif
    }

    window->show();
    window->raise();
}
Example #20
0
bool Layout::prepareLayout( bool &needMove, bool &needReparent )
{
    if ( !widgets.count() )
	return FALSE;
    for ( QWidget *w = widgets.first(); w; w = widgets.next() )
	w->raise();
    needMove = !layoutBase;
    needReparent = needMove || layoutBase->inherits( "QLayoutWidget" );
    if ( !layoutBase ) {
	layoutBase = WidgetFactory::create( WidgetDatabase::idFromClassName( "QLayoutWidget" ),
					    WidgetFactory::containerOfWidget( parent ) );
    } else {
	WidgetFactory::deleteLayout( layoutBase );
    }

    return TRUE;
}
void ossimQtSingleImageWindow::about()
{
    ossimString name = "ossimQtIviewAboutDialog";

    // First see if we already have a dialog open for this.
    QWidget* w = ossimQtEditorWidgetManager::instance()->getFromList(name);
    if (w)
    {
        w->raise();
        return;
    }

    w = new ossimQtIviewAboutDialog(this);

    // Add to the list so we don't make a duplicate dialog.
    ossimQtEditorWidgetManager::instance()->addToList(w);

    w->show();
}
Example #22
0
void Application::parseArgs( const QStringList &args )
{
	QStringList params = args;
	params.removeAll("-capi");
	params.removeAll("-cng");
	params.removeAll("-pkcs11");
	params.removeAll("-noNativeFileDialog");

	QWidget *w = new MainWindow();
#ifdef Q_OS_MAC
	w->installEventFilter( d->bar );
#endif
	w->addAction( d->closeAction );
	w->activateWindow();
	w->show();
	w->raise();
	if( !params.isEmpty() )
		QMetaObject::invokeMethod( w, "open", Q_ARG(QStringList,params) );
}
Example #23
0
void Dialog::showView()
{
	prepareView();

	QWidget * w = asQWidget();
	if (w->isVisible()) {
		w->raise();
		w->activateWindow();
	} else
		w->show();

	if (wantInitialFocus())
		w->setFocus();
	else {
		lyxview_->raise();
		lyxview_->activateWindow();
		lyxview_->setFocus();
	}
}
Example #24
0
bool SessionsManager::hasUrl(const QUrl &url, bool activate)
{
	for (int i = 0; i < m_managers.count(); ++i)
	{
		if (m_managers.at(i)->hasUrl(url, activate))
		{
			QWidget *window = qobject_cast<QWidget*>(m_managers.at(i)->parent());

			if (window)
			{
				window->raise();
				window->activateWindow();
			}

			return true;
		}
	}

	return false;
}
Example #25
0
// called when left-clicking the tray icon
// if the window is not the active one, show it if needed, and activate it
// (just like taskbar); otherwise hide it
void KSystemTray::activateOrHide()
{
    QWidget *pw = parentWidget();

    if(!pw)
        return;

#ifdef Q_WS_X11
    KWin::WindowInfo info1 = KWin::windowInfo(pw->winId(), NET::XAWMState | NET::WMState);
    // mapped = visible (but possibly obscured)
    bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
    //    - not mapped -> show, raise, focus
    //    - mapped
    //        - obscured -> raise, focus
    //        - not obscured -> hide
    if(!mapped)
        minimizeRestore(true);
    else
    {
        KWinModule module;
        for(QValueList< WId >::ConstIterator it = module.stackingOrder().fromLast(); it != module.stackingOrder().end() && (*it) != pw->winId(); --it)
        {
            KWin::WindowInfo info2 = KWin::windowInfo(*it, NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType);
            if(info2.mappingState() != NET::Visible)
                continue; // not visible on current desktop -> ignore
            if(!info2.geometry().intersects(pw->geometry()))
                continue; // not obscuring the window -> ignore
            if(!info1.hasState(NET::KeepAbove) && info2.hasState(NET::KeepAbove))
                continue; // obscured by window kept above -> ignore
            NET::WindowType type = info2.windowType(NET::NormalMask | NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask
                                                    | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask);
            if(type == NET::Dock || type == NET::TopMenu)
                continue; // obscured by dock or topmenu -> ignore
            pw->raise();
            KWin::activateWindow(pw->winId());
            return;
        }
        minimizeRestore(false); // hide
    }
#endif
}
void ossimQtSingleImageWindow::editImageChain()
{
    if (!theImageChain.valid())
    {
        QString caption = "Sorry:";
        QString text = "You must open an image first.";
        text += "  Use \"File->Open Image\"\n";
        QMessageBox::information( this,
                                  caption,
                                  text,
                                  QMessageBox::Ok );
        return;
    }

    ossimString name = "ossimQtImageChainEditorDialog";

    // First see if we already have a dialog open for this.
    QWidget* w = ossimQtEditorWidgetManager::instance()->getFromList(name,
                 this);
    if (w)
    {
        w->raise();
        return;
    }

    ossimQtImageChainEditorDialog* chainEditor
        = new ossimQtImageChainEditorDialog(this,
                                            name.c_str(),
                                            false,
                                            Qt::WDestructiveClose);
    chainEditor->setImageWidget(theImageWidget);
//   vector<ossimString> list;
//   getAllowedFilterList(list);
//   chainEditor->setAvailableFilterList(list);

    // Add to the list so we don't make a duplicate dialog.
    ossimQtEditorWidgetManager::instance()->addToList(chainEditor, this);

    chainEditor->show();
}
Example #27
0
/*
void TabDropDock::mousePressEvent(QMouseEvent *e)
{
  if (e->button() == Qt::LeftButton) m_startDragPos = e->pos();
}

void TabDropDock::mouseMoveEvent(QMouseEvent *e)
{
  if (e->buttons() & Qt::LeftButton)
  {
    int distance = (e->pos() - m_startDragPos).manhattanLength();
    if (distance >= QApplication::startDragDistance()) performDrag();
  }
}
*/
void TabDropDock::slotPerformDrag()
{
//  emit(signalFloatOrDockMe(this));
  QDrag *drag = new QDrag(this);
  QWidget *widget = currentWidget();
  if (widget)
  {
    WidgetMimeData *mimeData = new WidgetMimeData(widget);
    drag->setMimeData(mimeData);
    if (drag->exec(Qt::MoveAction) != Qt::MoveAction)
    {
      if (widget->parent() != 0)
      {
        widget->setParent(0);
        widget->setGeometry(QCursor::pos().x(),QCursor::pos().y(),width(),height());
        widget->show();
        widget->raise();
        widget->activateWindow();
//        removeTab(currentIndex());
      }
    }
  }
//  this->repaint();
}
Example #28
0
void StackLayout::setCurrentIndex(int index)
{
    QWidget *prev = currentWidget();
    QWidget *next = widget(index);
    if (!next || next == prev)
        return;

    _index = index;

    if(!parent()) return;

    bool reenableUpdates = false;
    QWidget *parent = parentWidget();

    if (parent && parent->updatesEnabled()) {
        reenableUpdates = true;
        parent->setUpdatesEnabled(false);
    }

    QWidget *fw = parent ? parent->window()->focusWidget() : 0;
    if (prev) {
        prev->clearFocus();
        if (_mode == StackOne)
            prev->hide();
    }

    next->raise();
    next->show();

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.

    if (parent) {
        if (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page
            // look for the best focus widget we can find
            if (QWidget *nfw = next->focusWidget())
                nfw->setFocus();
            else {
                // second best: first child widget in the focus chain
                QWidget *i = fw;
                while ((i = i->nextInFocusChain()) != fw) {
                    if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                        && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
                        && next->isAncestorOf(i)) {
                        i->setFocus();
                        break;
                    }
                }
                // third best: incoming widget
                if (i == fw )
                    next->setFocus();
            }
        }
    }
    if (reenableUpdates)
        parent->setUpdatesEnabled(true);

    if (_mode == StackOne)
      // expandingDirections() might have changed, so invalidate():
      invalidate();
}
Example #29
0
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
    static const QEvent::Type contextMenuTrigger =
        QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
        QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
    if (qApp->d_func()->inPopupMode()) {
        QWidget *activePopupWidget = qApp->activePopupWidget();
        QWidget *popup = activePopupWidget;
        QPoint mapped = event->pos();
        if (popup != m_widget)
            mapped = popup->mapFromGlobal(event->globalPos());
        bool releaseAfter = false;
        QWidget *popupChild  = popup->childAt(mapped);

        if (popup != qt_popup_down) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }

        switch (event->type()) {
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonDblClick:
            qt_button_down = popupChild;
            qt_popup_down = popup;
            break;
        case QEvent::MouseButtonRelease:
            releaseAfter = true;
            break;
        default:
            break; // nothing for mouse move
        }

        int oldOpenPopupCount = openPopupCount;

        if (popup->isEnabled()) {
            // deliver event
            qt_replay_popup_mouse_event = false;
            QWidget *receiver = popup;
            QPoint widgetPos = mapped;
            if (qt_button_down)
                receiver = qt_button_down;
            else if (popupChild)
                receiver = popupChild;
            if (receiver != popup)
                widgetPos = receiver->mapFromGlobal(event->globalPos());
            QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
            QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
            QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
            e.setTimestamp(event->timestamp());
            QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
        } else {
            // close disabled popups when a mouse button is pressed or released
            switch (event->type()) {
            case QEvent::MouseButtonPress:
            case QEvent::MouseButtonDblClick:
            case QEvent::MouseButtonRelease:
                popup->close();
                break;
            default:
                break;
            }
        }

        if (qApp->activePopupWidget() != activePopupWidget
            && qt_replay_popup_mouse_event) {
            if (m_widget->windowType() != Qt::Popup)
                qt_button_down = 0;
            if (event->type() == QEvent::MouseButtonPress) {
                // the popup disappeared, replay the mouse press event
                QWidget *w = QApplication::widgetAt(event->globalPos());
                if (w && !QApplicationPrivate::isBlockedByModal(w)) {
                    // activate window of the widget under mouse pointer
                    if (!w->isActiveWindow()) {
                        w->activateWindow();
                        w->raise();
                    }

                    QWindow *win = w->windowHandle();
                    if (!win)
                        win = w->nativeParentWidget()->windowHandle();
                    if (win && win->geometry().contains(event->globalPos())) {
                        const QPoint localPos = win->mapFromGlobal(event->globalPos());
                        QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
                        QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
                        e.setTimestamp(event->timestamp());
                        QApplication::sendSpontaneousEvent(win, &e);
                    }
                }
            }
            qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
        } else if (event->type() == contextMenuTrigger
                   && event->button() == Qt::RightButton
                   && (openPopupCount == oldOpenPopupCount)) {
            QWidget *popupEvent = popup;
            if (qt_button_down)
                popupEvent = qt_button_down;
            else if(popupChild)
                popupEvent = popupChild;
            QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
            QApplication::sendSpontaneousEvent(popupEvent, &e);
#endif
        }

        if (releaseAfter) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }
        return;
    }

    // modal event handling
    if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
        return;

    // which child should have it?
    QWidget *widget = m_widget->childAt(event->pos());
    QPoint mapped = event->pos();

    if (!widget)
        widget = m_widget;

    if (event->type() == QEvent::MouseButtonPress)
        qt_button_down = widget;

    QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                               qt_button_down, widget);

    if (!receiver) {
        if (event->type() == QEvent::MouseButtonRelease)
            QApplicationPrivate::mouse_buttons &= ~event->button();
        return;
    }
    if ((event->type() != QEvent::MouseButtonPress)
        || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {

        // The preceding statement excludes MouseButtonPress events which caused
        // creation of a MouseButtonDblClick event. QTBUG-25831
        QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(),
                               event->button(), event->buttons(), event->modifiers());
        QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event));
        translated.setTimestamp(event->timestamp());
        QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
                                            &qt_button_down, qt_last_mouse_receiver);
    }
#ifndef QT_NO_CONTEXTMENU
    if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
Example #30
0
CollectionWidget::CollectionWidget( QWidget* parent ):
        QWidget(parent)
{
    p = new CollectionWidgetPrivate;

    QPushButton *pushRandom =new QPushButton();
    QPixmap pixmap2(":shuffle.png");
    pushRandom->setIcon(QIcon(pixmap2));
    pushRandom->setIconSize(QSize(27,27));
    pushRandom->setMaximumWidth(40);
    pushRandom->setStyleSheet("QPushButton { border: none; padding: 0px; margin-left: 10px;max-height: 20px; margin-right: 4px;}");
    pushRandom->setToolTip(tr( "Random Tracks" ));

    p->searchEdit = new SearchEdit();
    p->searchEdit->setToolTip(tr( "Enter space-separated terms to filter collection" ));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    QWidget *headWidget = new QWidget(this);
    headWidget->setMaximumHeight(38);

    QHBoxLayout *headWidgetLayout = new QHBoxLayout;
    headWidgetLayout->setMargin(0);
    headWidgetLayout->setSpacing(1);

    headWidgetLayout->addSpacerItem(new QSpacerItem(10, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
    headWidgetLayout->addWidget(p->searchEdit);
    headWidgetLayout->addWidget(pushRandom);
    headWidget->setLayout(headWidgetLayout);

    p->updater = new CollectionUpdater();

    p->timer = new QTimer( this );
    p->timer->setInterval(300);
    p->timer->setSingleShot(true);

    p->collectiontree = new CollectionTree(this);
    p->modeSelect = new ModeSelector(p->collectiontree);

    headWidget->raise();
    mainLayout->addWidget(headWidget);

    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
 
    connect(pushRandom,SIGNAL(clicked()),
            p->collectiontree,SLOT(triggerRandomSelection()) );

    connect ( p->modeSelect , SIGNAL(modeChanged(ModeSelector::modeType)),
            this, SLOT(onModeSelected(ModeSelector::modeType)));

    connect( p->searchEdit, SIGNAL( textChanged( const QString& ) ),
             this,           SLOT( onSetFilterTimeout() ) );

    connect( p->searchEdit, SIGNAL( trackDropped(QString)),
             this,           SIGNAL( trackDropped(QString)) );

    connect( p->collectiontree, SIGNAL(selectionChanged(QList<Track*>)),
             this,           SIGNAL(selectionChanged(QList<Track*>)));

    connect( p->collectiontree, SIGNAL(wantLoad(QList<Track*>,QString)),
             this,           SIGNAL(wantLoad(QList<Track*>,QString)));

    connect( p->updater, SIGNAL(changesDone()), p->collectiontree, SLOT(createTrunk()));
    connect( p->collectiontree, SIGNAL(rescan()), p->updater, SLOT(scan()));

    connect( p->timer, SIGNAL(timeout()), SLOT(onSetFilter())  );

    setFocusProxy( p->collectiontree ); //default object to get focus
    setMaximumWidth(400);

    //Pogressbar for re-read collection
    p->progress = new ProgressBar(this);
    p->progress->setValue(0);
    p->progress->setStyleSheet("* { margin-bottom: 3px; }");

    mainLayout->addWidget(p->collectiontree);


    // Read config values
    QSettings settings;
    p->modeSelect->setMode( static_cast<ModeSelector::modeType>(settings.value("TreeMode",ModeSelector::MODENONE).toUInt()));


    p->collectiontree->createTrunk();
    setLayout(mainLayout);

    connect(p->updater, SIGNAL(progressChanged(int)), p->progress,SLOT(setValue(int)));
    connect(p->progress, SIGNAL(stopped()), p->updater,SLOT(stop()));
    p->modeSelect->show();
}