示例#1
0
void MsgViewBase::update()
{
    if (m_updated.empty())
        return;
    unsigned i;
    for (i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        unsigned id = messageId(s.left(n), client);
        list<Msg_Id>::iterator it;
        for (it = m_updated.begin(); it != m_updated.end(); ++it){
            if (((*it).id == id) && ((*it).client == client))
                break;
        }
        if (it != m_updated.end())
            break;
    }
    m_updated.clear();
    if (i >= (unsigned)paragraphs())
        return;
    QPoint p = QPoint(0, 0);
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    p = QPoint(0, viewport()->height());
    p = viewport()->mapToGlobal(p);
    p = mapFromGlobal(p);
    if (p.y() + 2 == height())
        pos = -1;
    unsigned start = i;
    list<Msg_Id> msgs;
    for (; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        unsigned id = messageId(s.left(n), client);
        list<Msg_Id>::iterator it;
        for (it = msgs.begin(); it != msgs.end(); ++it){
            if (((*it).id == id) && ((*it).client == client))
                break;
        }
        if (it != msgs.end())
            continue;
        Msg_Id m_id;
        m_id.id     = id;
        m_id.client = client;
        msgs.push_back(m_id);
    }
    int paraFrom, indexFrom;
    int paraTo, indexTo;
    getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
    setReadOnly(false);
    setSelection(start, 0, paragraphs() - 1, 0xFFFF);
    removeSelectedText();
    setReadOnly(true);
    QString text;
    for (list<Msg_Id>::iterator it = msgs.begin(); it != msgs.end(); ++it){
        Message *msg = History::load((*it).id, (*it).client.c_str(), m_id);
        if (msg == NULL)
            continue;
        bool bUnread = false;
        for (list<msg_id>::iterator itu = CorePlugin::m_plugin->unread.begin(); itu != CorePlugin::m_plugin->unread.end(); ++itu){
            msg_id &m = (*itu);
            if ((m.contact == msg->contact()) &&
                    (m.id == msg->id()) &&
                    (m.client == msg->client())){
                bUnread = true;
                break;
            }
        }
        text += messageText(msg, bUnread);
    }
    append(text);
    if (!CorePlugin::m_plugin->getOwnColors())
        setBackground(0);
    if ((paraFrom != paraTo) || (indexFrom != indexTo))
        setSelection(paraFrom, indexFrom, paraTo, indexTo);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
示例#2
0
void EditableTabBar::mouseDoubleClickEvent(QMouseEvent* event) {
    _edit.setText(tabText(currentIndex()));
    _edit.move(mapToGlobal(event->pos()));
}
示例#3
0
    MainWindow::MainWindow(QApplication* app)
		: main_page_(nullptr)
		, login_page_(nullptr)
#ifdef __APPLE__
        , accounts_page_(nullptr)
#endif //_APPLE__
		, app_(app)
		, event_filter_(new TitleWidgetEventFilter(this))
		, tray_icon_(new TrayIcon(this))
                , backgroundPixmap_(QPixmap())
        , Shadow_(0)
        , SkipRead_(false)
        , TaskBarIconHidden_(false)
        , liveChats_(new LiveChats(this))
	{
        Utils::InterConnector::instance().setMainWindow(this);

#ifdef _WIN32
        Utils::init_crash_handlers_in_core();
        core::dump::crash_handler chandler;
        chandler.set_process_exception_handlers();
        chandler.set_thread_exception_handlers();
#endif //_WIN32

		setStyleSheet(Utils::LoadStyle(":/main_window/main_window.qss", Utils::get_scale_coefficient(), true));
#ifdef __APPLE__
        mac_support_ = new MacSupport(this);
        mac_support_->enableMacCrashReport();
#endif

        app_->installNativeEventFilter(this);

        if (this->objectName().isEmpty())
            this->setObjectName(QStringLiteral("main_window"));
        this->resize(329, 331);
        QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
        sizePolicy.setHorizontalStretch(0);
        sizePolicy.setVerticalStretch(0);
        sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
        this->setSizePolicy(sizePolicy);
        this->setLayoutDirection(Qt::LeftToRight);
        this->setAutoFillBackground(false);
        main_widget_ = new QWidget(this);
        main_widget_->setObjectName(QStringLiteral("main_widget"));
        sizePolicy.setHeightForWidth(main_widget_->sizePolicy().hasHeightForWidth());
        main_widget_->setSizePolicy(sizePolicy);
        vertical_layout_ = new QVBoxLayout(main_widget_);
        vertical_layout_->setSpacing(0);
        vertical_layout_->setObjectName(QStringLiteral("verticalLayout_9"));
        vertical_layout_->setSizeConstraint(QLayout::SetDefaultConstraint);
        vertical_layout_->setContentsMargins(0, 0, 0, 0);
        title_widget_ = new QWidget(main_widget_);
        title_widget_->setObjectName(QStringLiteral("title_widget"));
        QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Fixed);
        sizePolicy1.setHorizontalStretch(0);
        sizePolicy1.setVerticalStretch(0);
        sizePolicy1.setHeightForWidth(title_widget_->sizePolicy().hasHeightForWidth());
        title_widget_->setSizePolicy(sizePolicy1);
        title_widget_->setProperty("TitleWidget", QVariant(true));
        horizontal_layout_ = new QHBoxLayout(title_widget_);
        horizontal_layout_->setSpacing(0);
        horizontal_layout_->setObjectName(QStringLiteral("horizontalLayout"));
        horizontal_layout_->setContentsMargins(0, 0, 0, 0);
        logo_ = new QPushButton(title_widget_);
        logo_->setObjectName(QStringLiteral("logo"));
        QSizePolicy sizePolicy2(QSizePolicy::Fixed, QSizePolicy::Fixed);
        sizePolicy2.setHorizontalStretch(0);
        sizePolicy2.setVerticalStretch(0);
        sizePolicy2.setHeightForWidth(logo_->sizePolicy().hasHeightForWidth());
        logo_->setSizePolicy(sizePolicy2);
        logo_->setProperty("WindowIcon", QVariant(true));
        horizontal_layout_->addWidget(logo_);
        title_ = new QLabel(title_widget_);
        title_->setObjectName(QStringLiteral("title"));
        title_->setProperty("Title", QVariant(true));
        horizontal_layout_->addWidget(title_);
        horizontal_spacer_ = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
        horizontal_layout_->addItem(horizontal_spacer_);
        hide_button_ = new QPushButton(title_widget_);
        hide_button_->setObjectName(QStringLiteral("hide_button"));
        hide_button_->setProperty("HideButton", QVariant(true));
        horizontal_layout_->addWidget(hide_button_);
        maximize_button_ = new QPushButton(title_widget_);
        maximize_button_->setObjectName(QStringLiteral("maximize_button"));
        sizePolicy2.setHeightForWidth(maximize_button_->sizePolicy().hasHeightForWidth());
        maximize_button_->setSizePolicy(sizePolicy2);
        maximize_button_->setProperty("MaximizeButton", QVariant(true));
        horizontal_layout_->addWidget(maximize_button_);
        close_button_ = new QPushButton(title_widget_);
        close_button_->setObjectName(QStringLiteral("close_button"));
        sizePolicy2.setHeightForWidth(close_button_->sizePolicy().hasHeightForWidth());
        close_button_->setSizePolicy(sizePolicy2);
        close_button_->setProperty("CloseButton", QVariant(true));
        horizontal_layout_->addWidget(close_button_);
        vertical_layout_->addWidget(title_widget_);
        stacked_widget_ = new BackgroundWidget(main_widget_, "");
        stacked_widget_->setObjectName(QStringLiteral("stacked_widget"));

        QPixmap p(":/resources/main_window/pat_100.png");
        setBackgroundPixmap(p, true);

        //Utils::InterConnector::instance().setMainWindow(this);
        get_qt_theme_settings()->setOrLoadDefaultTheme();
        vertical_layout_->addWidget(stacked_widget_);
        this->setCentralWidget(main_widget_);

        logo_->setText(QString());
        hide_button_->setText(QString());
        maximize_button_->setText(QString());
        close_button_->setText(QString());

        stacked_widget_->setCurrentIndex(-1);
        QMetaObject::connectSlotsByName(this);

        if (!get_gui_settings()->get_value(settings_keep_logged_in, true))// || !get_gui_settings()->contains_value(settings_keep_logged_in))
        {
            showLoginPage();
        }
        else
        {
            showMainPage();
        }

		title_widget_->installEventFilter(event_filter_);
		title_->setText("ICQ");
		title_->setAttribute(Qt::WA_TransparentForMouseEvents);
		logo_->setAttribute(Qt::WA_TransparentForMouseEvents);

		setWindowTitle("ICQ");
#ifdef _WIN32
        setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::WindowMinimizeButtonHint);
        fake_parent_window_ = Utils::create_fake_parent_window();
#else
        title_widget_->hide();
#endif

		title_->setMouseTracking(true);

		connect(hide_button_, SIGNAL(clicked()), this, SLOT(minimize()), Qt::QueuedConnection);
		connect(maximize_button_, SIGNAL(clicked()), this, SLOT(maximize()), Qt::QueuedConnection);
		connect(close_button_, SIGNAL(clicked()), this, SLOT(hideWindow()), Qt::QueuedConnection);

		hide_button_->setCursor(Qt::PointingHandCursor);
		maximize_button_->setCursor(Qt::PointingHandCursor);
		close_button_->setCursor(Qt::PointingHandCursor);

		connect(event_filter_, SIGNAL(doubleClick()), this, SLOT(maximize()), Qt::QueuedConnection);
		connect(event_filter_, SIGNAL(moveRequest(QPoint)), this, SLOT(moveRequest(QPoint)), Qt::QueuedConnection);

        connect(&Ui::GetDispatcher()->getVoipController(), SIGNAL(onVoipResetComplete()), this, SLOT(onVoipResetComplete()), Qt::QueuedConnection);

		connect(Ui::GetDispatcher(), SIGNAL(needLogin()), this, SLOT(showLoginPage()), Qt::DirectConnection);
		connect(&Utils::InterConnector::instance(), SIGNAL(showIconInTaskbar(bool)), this, SLOT(showIconInTaskbar(bool)), Qt::QueuedConnection);

        connect(this, SIGNAL(needActivate()), this, SLOT(activate()), Qt::QueuedConnection);

        connect(get_gui_settings(), SIGNAL(changed(QString)), this, SLOT(guiSettingsChanged(QString)), Qt::QueuedConnection);

		QFont f = QApplication::font();
		f.setStyleStrategy(QFont::PreferAntialias);
		QApplication::setFont(f);

        if (platform::is_windows())
        {
            int shadowWidth = get_gui_settings()->get_shadow_width();
            QBrush b = stacked_widget_->palette().background();
            QMatrix m;
            m.translate(shadowWidth, title_widget_->height() + shadowWidth);
            b.setMatrix(m);
            Shadow_ = new ShadowWindow(b, shadowWidth);
            QPoint pos = mapToGlobal(QPoint(rect().x(), rect().y()));
            Shadow_->move(pos.x(), pos.y());
            Shadow_->resize(rect().width(), rect().height());
            Shadow_->setActive(true);
            Shadow_->show();
        }

        initSettings();
#ifdef _WIN32
        DragAcceptFiles((HWND)winId(), TRUE);
#endif //_WIN32

        if (!get_gui_settings()->get_value<bool>(settings_show_in_taskbar, true))
            hide_taskbar_icon();

#ifdef __APPLE__
        mac_support_->enableMacUpdater();
        mac_support_->enableMacPreview(this->winId());
#endif

	}
void FormEditorGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
    if (rect().contains(event->pos())) {
        QGraphicsView::mouseReleaseEvent(event);
    } else {
        QPoint position = event->pos();
        QPoint topLeft = rect().topLeft();
        QPoint bottomRight = rect().bottomRight();
        position.rx() = qMax(topLeft.x(), qMin(position.x(), bottomRight.x()));
        position.ry() = qMax(topLeft.y(), qMin(position.y(), bottomRight.y()));
        QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(event->type(), position, mapToGlobal(position), event->button(), event->buttons(), event->modifiers());

        QGraphicsView::mouseReleaseEvent(mouseEvent);
        delete mouseEvent;
    }

    m_feedbackOriginPoint = QPoint();
}
示例#5
0
void PicViewerWindow::mouseMoveEvent(QMouseEvent *event)
{
    // 无边框窗体的边缘拖动resize方案参考了如下博客的代码
    // http://www.cnblogs.com/xufeiyang/p/3313104.html
    QPoint gloPoint = event->globalPos();
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());

    if (event->buttons() & Qt::LeftButton && clickOnFrame)
    {

        if(mouseDir != NONE) {
            QRect rMove(tl, rb);

            switch(mouseDir) {
            case LEFT:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                break;
            case RIGHT:
                rMove.setWidth(gloPoint.x() - tl.x());
                break;
            case UP:
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case DOWN:
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case LEFTTOP:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case RIGHTTOP:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setY(gloPoint.y());
                break;
            case LEFTBOTTOM:
                rMove.setX(gloPoint.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case RIGHTBOTTOM:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            default:
                break;
            }
            this->setGeometry(rMove);
        } else {
            //滚动条宽度都改成了1px,以是否可见滚动条为判别移动图片还是窗体
            //尚不能判断拖动的是图片还是窗体
            if (vScrollBar->isVisible() || hScrollBar->isVisible()) {
                int xvalue = event->x()-drag_pos.x();
                int yvalue = event->y()-drag_pos.y();
                vScrollBar->setValue(scrollBarValue.y()-yvalue);
                hScrollBar->setValue(scrollBarValue.x()-xvalue);
            } else {
                move(gloPoint - drag_pos);
            }
        }
        event->accept();
    }
}
示例#6
0
/*!
 * \brief TextEditor::showContextMenu
 * Create a context menu.
 * \param point
 */
void TextEditor::showContextMenu(QPoint point)
{
  QMenu *pMenu = BaseEditor::createStandardContextMenu();
  pMenu->exec(mapToGlobal(point));
  delete pMenu;
}
示例#7
0
TQRect RegExpWidget::selectionRect() const
{
  return TQRect( mapToGlobal( TQPoint(0,0) ), size() );
}
示例#8
0
void PanIconWidget::setCursorToLocalRegionSelectionCenter(void)
{
    QCursor::setPos(mapToGlobal(m_localRegionSelection.center()));
}
示例#9
0
文件: galagv.cpp 项目: abho/Distanz
void GalaGV::onContextMenuRequest(const QPoint &pos)
{

    QGraphicsItem *item = itemAt(pos);
    QGraphicsEllipseItem *eSystemItem;
    ESystem  e;

    SendMenu menu(ShipTreeWidget::tree());
    QMenu *m  = menu.menu();
    QAction *openSys = m->addAction("openSys");
    QAction *openLog = m->addAction("openLog");
    QAction *setCheckd = m->addAction("check");
    QAction *setWerf = m->addAction("werft");
    QAction *clearChecked = m->addAction("clear all checked");
    setCheckd->setCheckable(true);
    setWerf->setCheckable(true);

    const QHash<QString,QGraphicsEllipseItem*> &esysteme = mData->eSysteme.value(mData->showESysteme.first+";"+QString::number(mData->gala));

    if(!mData->showESysteme.second || esysteme.size() == 0)
        clearChecked->setEnabled(false);

    if(item == NULL){
        openSys->setEnabled(false);
        openLog->setEnabled(false);
        setCheckd->setEnabled(false);
        setWerf->setEnabled(false);
    } else {
        if(!mData->mPlayerLogPlanis.contains(item))
            openLog->setEnabled(false);

        eSystemItem =esysteme.value(item->data(ID).toString());
        if(eSystemItem == NULL || !mData->showESysteme.second){
            setCheckd->setEnabled(false);
            setWerf->setEnabled(false);
        }else {
            e=eSystemItem->data(Esystem).value<ESystem>();
            setCheckd->setChecked(e.isChecked);
            setWerf->setChecked(e.isWerft);
        }
    }



    if( eSystemItem == NULL || !mData->showESysteme.second)
        menu.setDisable(true);

    do {
        QAction *ret = m->exec(mapToGlobal(pos));
        if(ret == openSys){
            emit loadPage("http://www.omega-day.com/game/?op=system&sys="+item->data(Qt::UserRole).toString());
        }else if (ret == openLog){
            emit loadPage("http://www.omega-day.com/game/"+item->data(Qt::UserRole+1).toString());
        } else if(ret == setCheckd){
            setChecked(eSystemItem,setCheckd->isChecked());
        } else if(ret == clearChecked){
            int ret =QMessageBox::warning(this,"muh","wirklich löschen",QMessageBox::Yes,QMessageBox::No);
            if(ret == QMessageBox::Yes)
                clearAllChecked();

        }else if (ret == setWerf) {
            setWerft(eSystemItem,setWerf->isChecked());
        }else if( menu.checkSendClicked(ret)){
           const  QStringList & l = menu.checkedID();
            const QString &oldID = menu.orbitID();
            if(l.size()>0){
                QString planiID = eSystemItem->data(Esystem).value<ESystem>().planiID;
                if(l.size() == 1)
                    emit sendShip(l.first(),oldID,planiID);
                else
                    emit sendShips(l,planiID);
            }
        }
    }while(!menu.exit());
}
示例#10
0
void RoutingInputWidget::showMenu()
{
    d->m_menu->exec( mapToGlobal( QPoint( 0, size().height() ) ) );
}
示例#11
0
void CountryList::mouseMoveEvent(QMouseEvent *e) {
	_mouseSel = true;
	_mousePos = mapToGlobal(e->pos());
	onUpdateSelected(true);
}
示例#12
0
文件: slider.cpp 项目: Adamiko/los
void Slider::getScrollMode(QPoint &p, const Qt::MouseButton &button, int &scrollMode, int &direction)
{
	if (cursorHoming() && button == Qt::LeftButton)
	{
		if (d_sliderRect.contains(p))
		{
			scrollMode = ScrMouse;
			direction = 0;

			int mp = 0;
			QRect cr;
			QPoint cp;
			int ipos, dist1;
			double rpos;
			int lineDist;

			if (d_bwTrough > 0)
				cr.setRect(d_sliderRect.x() + d_bwTrough,
					d_sliderRect.y() + d_bwTrough,
					d_sliderRect.width() - 2 * d_bwTrough,
					d_sliderRect.height() - 2 * d_bwTrough);
			else
				cr = d_sliderRect;

			rpos = (value() - minValue()) / (maxValue() - minValue());

			lineDist = d_borderWidth - 1;
			if (lineDist < 1) lineDist = 1;

			if (d_orient == Qt::Horizontal)
			{
				dist1 = int(double(cr.width() - d_thumbLength) * rpos);
				ipos = cr.x() + dist1;
				mp = ipos + d_thumbHalf;

				p.setX(mp);
				cp = mapToGlobal(QPoint(mp, p.y()));
			}
			else
			{
				dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos));
				ipos = cr.y() + dist1;
				mp = ipos + d_thumbHalf;
				p.setY(mp);
				cp = mapToGlobal(QPoint(p.x(), mp));
			}
			cursor().setPos(cp.x(), cp.y());
		}
	}
	else
	{
		int currentPos;
		if (d_orient == Qt::Horizontal)
			currentPos = p.x();
		else
			currentPos = p.y();

		if (d_sliderRect.contains(p))
		{
			if ((currentPos > markerPos - d_thumbHalf)
					&& (currentPos < markerPos + d_thumbHalf))
			{
				scrollMode = ScrMouse;
				direction = 0;
			}
			else
			{
				scrollMode = ScrPage;
				if (((currentPos > markerPos) && (d_orient == Qt::Horizontal))
						|| ((currentPos <= markerPos) && (d_orient != Qt::Horizontal)))
					direction = 1;
				else
					direction = -1;
			}
		}
		else
		{
			scrollMode = ScrNone;
			direction = 0;
		}

	}
}
示例#13
0
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tDataSourcesDialog::contextMenuEvent( QContextMenuEvent* pEvent )
{
    tMenu& menu = *new tMenu( this );
    menu.AddAction( m_pSelectAct );
    menu.AddAction( m_pConfigureAct );
    if (m_SelectedCategory == DATA_CATEGORY_ENGINE && m_SelectedInstance == -1 ) //engine category only
    {
        menu.AddAction( m_pEngineNumSetAct );
        m_pEngineNumSetAct->SetIndex(tDigitalData::NumInstances(DATA_CATEGORY_ENGINE) - 1);
    }

    if (m_SelectedCategory == DATA_CATEGORY_TRANSMISSION && m_SelectedInstance == -1 ) // transmissions are not tied to engines in this advanced menu 
    {
        menu.AddAction( m_pTransNumSetAct );
        m_pTransNumSetAct->SetIndex(tDigitalData::NumInstances(DATA_CATEGORY_TRANSMISSION) - 1);
    }

    if (m_SelectedCategory == DATA_CATEGORY_FUEL_TANK && m_SelectedInstance == -1)
    {
        menu.AddAction( m_pTankNumSetAct );
        m_pTankNumSetAct->SetIndex(tDigitalData::NumInstances(DATA_CATEGORY_FUEL_TANK) - 1);
    }

    if (m_SelectedCategory == DATA_CATEGORY_TRIM_TAB)
    {
        menu.AddAction( m_pTrimTabsNumSetAct );
        m_pTrimTabsNumSetAct->SetIndex(tDigitalData::NumInstances(DATA_CATEGORY_TRIM_TAB) - 1);
    }

    //m_pTreeView->selectedIndexes()
    menu.AddSeparator();
    menu.AddAction( m_pRenameAct );
    menu.AddAction( m_pNewInstanceAct );
    menu.AddAction( m_pRemoveAct );

    if ( m_pScopeAct != 0 )
    {
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
        {
            menu.AddAction( m_pScopeAct );
        }
    }
    menu.AddSeparator();
    if ( m_pAutoSelectAct != 0 )
    {
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
        {
            menu.AddAction( m_pAutoSelectAct );
        }
    }
    if ( m_pAutoConfigureAct != 0 )
    {
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
        {
            menu.AddAction( m_pAutoConfigureAct );
        }
    }
    if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
    {
        menu.AddAction( m_pGlobalResetAct );
    }
    if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
    {
        menu.AddAction( m_pLocalResetAct );
    }
    menu.SetDefaultAction( m_pSelectAct );
    menu.ShowAndDeleteOnClose( mapToGlobal( pEvent->pos() ) );
}
示例#14
0
void *MsgViewBase::processEvent(Event *e)
{
    if ((e->type() == EventRewriteMessage) || (e->type() == EventMessageRead)){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        unsigned i;
        for (i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            if ((messageId(s.left(n), client) == msg->id()) && (client == msg->client()))
                break;
        }
        if (i >= (unsigned)paragraphs())
            return NULL;
        Msg_Id id;
        id.id     = msg->id();
        id.client = msg->client();
        m_updated.push_back(id);
        QTimer::singleShot(0, this, SLOT(update()));
        return NULL;
    }
    if (e->type() == EventCutHistory){
        CutHistory *ch = (CutHistory*)(e->param());
        if (ch->contact != m_id)
            return NULL;

        bool bDelete = false;
        vector<unsigned> start_pos;
        vector<unsigned> end_pos;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            unsigned id = messageId(s.left(n), client);
            if ((client == ch->client) && (id >= ch->from) && (id < ch->from + ch->size)){
                if (!bDelete){
                    bDelete = true;
                    start_pos.push_back(i);
                }
            }else{
                if (bDelete){
                    bDelete = false;
                    end_pos.push_back(i);
                }
            }
        }
        if (bDelete)
            end_pos.push_back(paragraphs());
        if (start_pos.size()){
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            QPoint p = QPoint(0, 0);
            p = mapToGlobal(p);
            p = viewport()->mapFromGlobal(p);
            int x, y;
            viewportToContents(p.x(), p.y(), x, y);
            int para;
            int pos = charAt(QPoint(x, y), &para);
            setReadOnly(false);
            for (unsigned i = 0; i < start_pos.size(); i++){
                setSelection(start_pos[i], 0, end_pos[i], 0);
                removeSelectedText();
                if ((unsigned)pos >= start_pos[i])
                    pos = end_pos[i] - start_pos[i];
            }
            if ((paraFrom == -1) && (paraTo == -1)){
                if (pos == -1){
                    scrollToBottom();
                }else{
                    setCursorPosition(para, pos);
                    ensureCursorVisible();
                }
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            setReadOnly(true);
            repaint();
        }
        m_cut.push_back(*ch);
        return NULL;
    }
    if (e->type() == EventMessageDeleted){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client()))
                continue;
            string ss;
            ss = text(i).local8Bit();
            log(L_DEBUG, "?: %s", ss.c_str());

            unsigned j;
            for (j = i + 1; j < (unsigned)paragraphs(); j++){
                QString s = text(j);
                ss = text(j).local8Bit();
                log(L_DEBUG, ">: %s", ss.c_str());
                int n = s.find(MSG_ANCHOR);
                if (n < 0)
                    continue;
                s = s.mid(n + strlen(MSG_ANCHOR));
                n = s.find("\"");
                if (n < 0)
                    continue;
                string client;
                if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client()))
                    break;
            }
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            unsigned pos = 0xFFFF;
            if (j == (unsigned)paragraphs()){
                j++;
                pos = 0;
            }
            setSelection(i, 0, j - 1, pos);
            setReadOnly(false);
            removeSelectedText();
            setReadOnly(true);
            if ((paraFrom == -1) && (paraTo == -1)){
                scrollToBottom();
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            break;
        }
        return NULL;
    }
    if (e->type() == EventHistoryConfig){
        unsigned id = (unsigned)(e->param());
        if (id && (id != m_id))
            return NULL;
        reload();
    }
    if (e->type() == EventHistoryColors)
        setColors();
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED);
            if (!hasSelectedText())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                unsigned type = msg->baseType();
                delete msg;
                CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type);
                if (def == NULL)
                    return NULL;
                cmd->icon = def->icon;
                cmd->flags &= ~COMMAND_CHECKED;
                return e->param();
            }
            return NULL;
        case CmdMsgSpecial:
            msg = currentMessage();
            if (msg){
                Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand);
                CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process());

                unsigned n = 0;
                MessageDef *mdef = NULL;
                unsigned type = msg->baseType();
                const CommandDef *cmdsSpecial = NULL;
                CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                if (msgCmd)
                    mdef = (MessageDef*)(msgCmd->param);

                if (mdef){
                    if (msg->getFlags() & MESSAGE_RECEIVED){
                        cmdsSpecial = mdef->cmdReceived;
                    }else{
                        cmdsSpecial = mdef->cmdSent;
                    }
                    if (cmdsSpecial)
                        for (const CommandDef *d = cmdsSpecial; d->text; d++)
                            n++;
                }

                {
                    CommandsList it(*cmdsMsg, true);
                    while (++it)
                        n++;
                }
                if (n == 0)
                    return NULL;

                n++;
                CommandDef *cmds = new CommandDef[n];
                memset(cmds, 0, sizeof(CommandDef) * n);
                n = 0;
                if (cmdsSpecial){
                    for (const CommandDef *d = cmdsSpecial; d->text; d++){
                        cmds[n] = *d;
                        cmds[n].id = CmdMsgSpecial + n;
                        n++;
                    }
                }
                CommandDef *c;
                CommandsList it(*cmdsMsg, true);
                while ((c = ++it) != NULL){
                    CommandDef cmd = *c;
                    cmd.menu_id = MenuMsgCommand;
                    cmd.param   = msg;
                    Event e(EventCheckState, &cmd);
                    if (!e.process())
                        continue;
                    cmd.flags &= ~COMMAND_CHECK_STATE;
                    cmds[n++] = cmd;
                }
                cmd->param = cmds;
                cmd->flags |= COMMAND_RECURSIVE;
                delete msg;
                return e->param();
            }
            return NULL;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCutHistory:
            msg = currentMessage();
            if (msg){
                History::cut(msg, 0, 0);
                delete msg;
                return e->param();
            }
            return NULL;
        case CmdDeleteMessage:
            msg = currentMessage();
            if (msg){
                History::del(msg);
                delete msg;
                return e->param();
            }
            return NULL;
        case CmdCopy:
            copy();
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                msg->setFlags(msg->getFlags() | MESSAGE_OPEN);
                Event eOpen(EventOpenMessage, &msg);
                eOpen.process();
                delete msg;
                return e->param();
            }
            return NULL;
        default:
            msg = currentMessage();
            if (msg){
                if (cmd->id >= CmdMsgSpecial){
                    MessageDef *mdef = NULL;
                    unsigned type = msg->baseType();
                    CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                    if (msgCmd)
                        mdef = (MessageDef*)(msgCmd->param);
                    const CommandDef *cmds = NULL;
                    if (mdef){
                        if (msg->getFlags() & MESSAGE_RECEIVED){
                            cmds = mdef->cmdReceived;
                        }else{
                            cmds = mdef->cmdSent;
                        }
                    }

                    if (cmds){
                        unsigned n = cmd->id - CmdMsgSpecial;
                        for (const CommandDef *d = cmds; d->text; d++){
                            if (n-- == 0){
                                CommandDef cmd = *d;
                                cmd.param = msg;
                                Event eCmd(EventCommandExec, &cmd);
                                eCmd.process();
                                return e->param();
                            }
                        }
                    }
                }
                Command c;
                c->id = cmd->id;
                c->menu_id = MenuMsgCommand;
                c->param = msg;
                Event e(EventCommandExec, c);
                void *res = e.process();
                delete msg;
                return res;
            }
            return NULL;
        }
    }
    return NULL;
}
示例#15
0
void NavigationBar::contextMenuRequested(const QPoint &pos)
{
    QMenu menu;
    m_window->createToolbarsMenu(&menu);
    menu.exec(mapToGlobal(pos));
}
示例#16
0
void QgsWelcomePage::showContextMenuForProjects( QPoint point )
{
  QModelIndex index = mRecentProjectsListView->indexAt( point );
  if ( !index.isValid() )
    return;

  bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool();
  QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString();
  if ( path.isEmpty() )
    return;

  bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled;

  QMenu *menu = new QMenu( this );

  if ( enabled )
  {
    if ( !pin )
    {
      QAction *pinAction = new QAction( tr( "Pin to List" ), menu );
      connect( pinAction, &QAction::triggered, this, [this, index]
      {
        mModel->pinProject( index );
        emit projectPinned( index.row() );
      } );
      menu->addAction( pinAction );
    }
    else
    {
      QAction *pinAction = new QAction( tr( "Unpin from List" ), menu );
      connect( pinAction, &QAction::triggered, this, [this, index]
      {
        mModel->unpinProject( index );
        emit projectUnpinned( index.row() );
      } );
      menu->addAction( pinAction );
    }
    QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
    connect( openFolderAction, &QAction::triggered, this, [path]
    {
      QFileInfo fi( path );
      QString folder = fi.path();
      QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
    } );
    menu->addAction( openFolderAction );
  }
  else
  {
    QAction *rescanAction = new QAction( tr( "Refresh" ), menu );
    connect( rescanAction, &QAction::triggered, this, [this, index]
    {
      mModel->recheckProject( index );
    } );
    menu->addAction( rescanAction );
  }
  QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu );
  connect( removeProjectAction, &QAction::triggered, this, [this, index]
  {
    mModel->removeProject( index );
    emit projectRemoved( index.row() );
  } );
  menu->addAction( removeProjectAction );

  menu->popup( mapToGlobal( point ) );
}
示例#17
0
void Panel::onContextMenuRequest(QPoint point)
{
	QMenu* contextMenu = new QMenu(this);
	addDockActions(contextMenu);
	contextMenu->exec(mapToGlobal(point));
}
示例#18
0
void CallStackView::contextMenuSlot(const QPoint pos)
{
    QMenu wMenu(this); //create context menu
    mMenuBuilder->build(&wMenu);
    wMenu.exec(mapToGlobal(pos)); //execute context menu
}
示例#19
0
void plotsDialog::showContextMenu(const QPoint &pos)
{
    contextMenu->exec(mapToGlobal(pos));
}
 void setMousePosition(int x, int y)
 {
   QCursor::setPos( mapToGlobal(QPoint(x,y)) );
 }
示例#21
0
文件: FxLine.cpp 项目: Cubiicle/lmms
void FxLine::displayHelp()
{
	QWhatsThis::showText( mapToGlobal( rect().bottomRight() ),
								whatsThis() );
}
示例#22
0
void Storage::mouseMoveEvent(QMouseEvent *anEvent)
{
    QPoint pos = anEvent->pos() / scale_;
    if (anEvent->pos().x() < 0)
        pos.setX(0);

    if (width() < anEvent->pos().x())
        pos.setX(width() - 1);

    if (anEvent->pos().y() < 0)
        pos.setY(0);


    if (height() < anEvent->pos().y())
        pos.setY(height() - 1);

    /* изменяем прямоугольник  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        BoundingBoxTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerBoundBox(pos, prev_cursor_pos_, rect);
    }

    /* изменяем эллипс  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        EllipseTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerEllipse(pos, prev_cursor_pos_, ell);
    }

    /* изменяем стрелу  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        ArrowTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerArrow(pos, prev_cursor_pos_, arrow);
    }

    /* перемещаем последнюю точку(курсор) многоугольника до создания(точка зафиксирется кликом) новой */
    if (PolygonTool == tool_ &&
        NewSelection == state_ &&
        (anEvent->buttons() & Qt::LeftButton))
    {
        QPolygon tmp = poly.getCoordinates();
        tmp.setPoint(tmp.count() - 1, pos);
        poly.setCoordinates(tmp);
        repaint_needed_ = 1;
    }

//    if (-1 != focused_selection_ &&
//        !(anEvent->buttons() & Qt::LeftButton)) {
//        checkForPoints(&pos);
//    }
//here now 2
    /* изменяем многоульник */
//    if (-1 != hovered_point_.figureID &&
//        !list_polygon_->isEmpty() &&
//        PolyFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton) &&
//        hovered_point_.figureID == focused_selection_)
//    {
//        polygon_.poly.clear();
//        polygon_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;
//        Polygon *poly = list_polygon_->at(hovered_point_.figureID);

//        poly->poly.setPoint(hovered_point_.pointID, pos);

//        for(int i=0;i< list_polygon_->at(hovered_point_.figureID)->poly.count();++i)
//        {
//            if(i!=hovered_point_.pointID)
//                polygon_.poly  << list_polygon_->at(hovered_point_.figureID)->poly.point(i);
//            else
//                polygon_.poly << pos;
//        }
//        qDebug() << "polygon_.poly =" << polygon_.poly;

//        repaint_needed_ = 1;
//    }

    /* изменяем прямоульник */
//    if (-1 != hovered_point_.figureID &&
//        !list_bounding_box_->isEmpty() &&
//        RectFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        bounding_box_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        bounding_box_.rect.setTopLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.topLeft());
//        bounding_box_.rect.setTopRight(list_bounding_box_->at(hovered_point_.figureID)->rect.topRight());
//        bounding_box_.rect.setBottomRight(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomRight());
//        bounding_box_.rect.setBottomLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomLeft());
//        BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            rect->rect.setTopLeft(pos);
//            bounding_box_.rect.setTopLeft(pos);
//            qDebug() << "rect->rect.topLeft" << rect->rect.topLeft();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            rect->rect.setTopRight(pos);
//            bounding_box_.rect.setTopRight(pos);
//            qDebug() << "rect->rect.topRight" << rect->rect.topRight();
//        }
//        else if (2 == hovered_point_.pointID)
//        {
//            rect->rect.setBottomRight(pos);
//            bounding_box_.rect.setBottomRight(pos);
//            qDebug() << "rect->rect.bottomRight" << rect->rect.bottomRight();
//        }
//        else if (3 == hovered_point_.pointID)
//        {
//            rect->rect.setBottomLeft(pos);
//            bounding_box_.rect.setBottomLeft(pos);
//            qDebug() << "rect->rect.bottomLeft" << rect->rect.bottomLeft();
//        }
//        repaint_needed_ = 1;
//    }

//    /* изменяем эллипс */
//    if (-1 != hovered_point_.figureID &&
//        !list_ellipse_->isEmpty() &&
//        EllipseFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        ellipse_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        ellipse_.rect.setTopLeft(list_ellipse_->at(hovered_point_.figureID)->rect.topLeft());
//        ellipse_.rect.setTopRight(list_ellipse_->at(hovered_point_.figureID)->rect.topRight());
//        ellipse_.rect.setBottomRight(list_ellipse_->at(hovered_point_.figureID)->rect.bottomRight());
//        ellipse_.rect.setBottomLeft(list_ellipse_->at(hovered_point_.figureID)->rect.bottomLeft());
//        Ellipse *ell = list_ellipse_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            ell->rect.setTopLeft(pos);
//            ellipse_.rect.setTopLeft(pos);
//            qDebug() << "rect->rect.topLeft" << ell->rect.topLeft();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            ell->rect.setTopRight(pos);
//            ellipse_.rect.setTopRight(pos);
//            qDebug() << "rect->rect.topRight" << ell->rect.topRight();
//        }
//        else if (2 == hovered_point_.pointID)
//        {
//            ell->rect.setBottomRight(pos);
//            ellipse_.rect.setBottomRight(pos);
//            qDebug() << "rect->rect.bottomRight" << ell->rect.bottomRight();
//        }
//        else if (3 == hovered_point_.pointID)
//        {
//            ell->rect.setBottomLeft(pos);
//            ellipse_.rect.setBottomLeft(pos);
//            qDebug() << "rect->rect.bottomLeft" << ell->rect.bottomLeft();
//        }
//        repaint_needed_ = 1;
//    }

//    /* изменяем стрелу */
//    if (-1 != hovered_point_.figureID &&
//        !list_arrow_->isEmpty() &&
//        ArrowFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        arrow_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        arrow_.line.setP1(list_arrow_->at(hovered_point_.figureID)->line.p1());
//        arrow_.line.setP2(list_arrow_->at(hovered_point_.figureID)->line.p2());
//        Arrow *arrow = list_arrow_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            arrow->line.setP1(pos);
//            arrow_.line.setP1(pos);
//            qDebug() << "arrow->line.p1" << arrow->line.p1();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            arrow->line.setP2(pos);
//            arrow_.line.setP2(pos);
//            qDebug() << "arrow->line.p2" << arrow->line.p2();
//        }
//        repaint_needed_ = 1;
//    }

    /* когда изображение слишком большое(необходима прокрутка) */
    if ((anEvent->buttons() & Qt::MiddleButton) &&
        (scroll_area_->size().height() < size().height() ||
        scroll_area_->size().width() < size().width()))
    {
        QPoint globPos = mapToGlobal(pos);
        QPoint prev = mapToGlobal(prev_cursor_pos_);
        int horValue = scroll_area_->horizontalScrollBar()->value();
//        scroll_area_->horizontalScrollBar()
        int verValue = scroll_area_->verticalScrollBar()->value();


        QPoint delta = globPos - prev;
        prev_cursor_pos_ = pos;

        horValue += delta.x();
        verValue += delta.y();

        scroll_area_->horizontalScrollBar()->setValue(horValue);
        scroll_area_->verticalScrollBar()->setValue(verValue);
    }

    if (repaint_needed_) {
        update();
        repaint_needed_ = 0;
    }
}
void FormEditorGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
    if (rect().contains(event->pos())) {
        QGraphicsView::mouseMoveEvent(event);
    } else {
        QPoint position = event->pos();
        QPoint topLeft = rect().topLeft();
        QPoint bottomRight = rect().bottomRight();
        position.rx() = qMax(topLeft.x(), qMin(position.x(), bottomRight.x()));
        position.ry() = qMax(topLeft.y(), qMin(position.y(), bottomRight.y()));
        QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(event->type(), position, mapToGlobal(position), event->button(), event->buttons(), event->modifiers());

        QGraphicsView::mouseMoveEvent(mouseEvent);
        delete mouseEvent;
    }

    // Keeps the feedback bubble within screen boundraries
    int tx = qMin(width() - 114,  qMax(16, event->pos().x() + 50));
    int ty = qMin(height() - 45, qMax(10, event->pos().y() - 70));
    m_feedbackOriginPoint = QPoint(tx, ty);
}
示例#24
0
void ListView::showCustomContextMenu(const QPoint &pos)
{
    if (menu) {
        menu->popup(mapToGlobal(pos));
    }
}
示例#25
0
文件: webview.cpp 项目: mariuz/fram
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = new QMenu(this);

    QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());

    if (!r.linkUrl().isEmpty()) {
        QAction *newWindowAction = menu->addAction(tr("Open in New &Window"), this, SLOT(openActionUrlInNewWindow()));
        newWindowAction->setData(r.linkUrl());
        QAction *newTabAction = menu->addAction(tr("Open in New &Tab"), this, SLOT(openActionUrlInNewTab()));
        newTabAction->setData(r.linkUrl());
        menu->addSeparator();
        menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk()));
        menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl());
        menu->addSeparator();
        if (!page()->selectedText().isEmpty())
            menu->addAction(pageAction(QWebPage::Copy));
        menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard()));
    }

    if (!r.imageUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();
        QAction *newWindowAction = menu->addAction(tr("Open Image in New &Window"), this, SLOT(openActionUrlInNewWindow()));
        newWindowAction->setData(r.imageUrl());
        QAction *newTabAction = menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openActionUrlInNewTab()));
        newTabAction->setData(r.imageUrl());
        menu->addSeparator();
        menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk()));
        menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard()));
        menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString());
        menu->addSeparator();
        menu->addAction(tr("Block Image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString());
    }

    if (!page()->selectedText().isEmpty()) {
        if (menu->isEmpty()) {
            menu->addAction(pageAction(QWebPage::Copy));
        } else {
            menu->addSeparator();
        }
        QMenu *searchMenu = menu->addMenu(tr("Search with..."));

        QList<QString> list = ToolbarSearch::openSearchManager()->allEnginesNames();
        for (int i = 0; i < list.count(); ++i) {
            QString name = list.at(i);
            OpenSearchEngine *engine = ToolbarSearch::openSearchManager()->engine(name);
            QAction *action = new OpenSearchEngineAction(engine, searchMenu);
            searchMenu->addAction(action);
            action->setData(name);
        }

        connect(searchMenu, SIGNAL(triggered(QAction *)), this, SLOT(searchRequested(QAction *)));
    }

    QWebElement element = r.element();
    if (!element.isNull()
        && element.tagName().toLower() == QLatin1String("input")
        && element.attribute(QLatin1String("type"), QLatin1String("text")) == QLatin1String("text")) {
        if (menu->isEmpty()) {
            menu->addAction(pageAction(QWebPage::Copy));
        } else {
            menu->addSeparator();
        }

        QVariant variant;
        variant.setValue(element);
        menu->addAction(tr("Add to the toolbar search"), this, SLOT(addSearchEngine()))->setData(variant);
    }

    if (menu->isEmpty()) {
        delete menu;
        menu = page()->createStandardContextMenu();
    } else {
        if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled))
            menu->addAction(pageAction(QWebPage::InspectElement));
    }

    if (!menu->isEmpty()) {
        if (BrowserMainWindow::parentWindow(tabWidget())->menuBar()->isHidden()) {
            menu->addSeparator();
            menu->addAction(BrowserMainWindow::parentWindow(tabWidget())->showMenuBarAction());
        }

        menu->exec(mapToGlobal(event->pos()));
        delete menu;
        return;
    }
    delete menu;

    QWebView::contextMenuEvent(event);
}
示例#26
0
void CWizDocumentListView::contextMenuEvent(QContextMenuEvent * e)
{
    // reset permission
    resetPermission();
    m_menu->popup(mapToGlobal(e->pos()));
}
示例#27
0
void *MsgViewBase::processEvent(Event *e)
{
    if (e->type() == EventMessageRead){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_HREF);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_HREF));
            n = s.find("\"");
            if (n < 0)
                continue;
            s = s.left(n);
            unsigned id = atol(getToken(s, ',').latin1());
            if (id != msg->id())
                continue;
            getToken(s, ',');
            if (s != msg->client())
                continue;
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            setSelection(i, 0, i, 0xFFFF);
            setBold(false);
            if ((paraFrom == -1) && (paraTo == -1)){
                removeSelection();
                scrollToBottom();
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            break;
        }
        return NULL;
    }
    if (e->type() == EventHistoryConfig){
        unsigned id = (unsigned)(e->param());
        if (id && (id != m_id))
            return NULL;
        QString t;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_HREF);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_HREF));
            n = s.find("\"");
            if (n < 0)
                continue;
            s = s.left(n);
            unsigned id = atol(getToken(s, ',').latin1());
            getToken(s, ',');
            Message *msg = History::load(id, s.utf8(), m_id);
            if (msg == NULL)
                continue;
            t += messageText(msg);
            delete msg;
        }
        QPoint p = QPoint(0, height());
        p = mapToGlobal(p);
        p = viewport()->mapFromGlobal(p);
        int x, y;
        viewportToContents(p.x(), p.y(), x, y);
        int para;
        int pos = charAt(QPoint(x, y), &para);
        setText(t);
        setBackground(0);
        if (pos == -1){
            scrollToBottom();
        }else{
            setCursorPosition(para, pos);
            ensureCursorVisible();
        }
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED);
            if (!hasSelectedText())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                unsigned type = msg->type();
                delete msg;
                for (;;){
                    CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type);
                    if (def == NULL){
                        return NULL;
                    }
                    MessageDef *mdef = (MessageDef*)(def->param);
                    if (mdef->base_type){
                        type = mdef->base_type;
                        continue;
                    }
                    cmd->icon = def->icon;
                    cmd->flags &= ~COMMAND_CHECKED;
                    return e->param();
                }
            }
            return NULL;
        case CmdMsgSpecial:
            msg = currentMessage();
            if (msg){
                Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand);
                CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process());

                unsigned n = 0;
                MessageDef *mdef = NULL;
                if (msg->getFlags() & MESSAGE_RECEIVED){
                    unsigned type = msg->type();
                    for (;;){
                        CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                        if (msgCmd == NULL)
                            break;
                        mdef = (MessageDef*)(msgCmd->param);
                        if (mdef->base_type == 0)
                            break;
                        type = mdef->base_type;
                    }
                }
                if (mdef && mdef->cmd){
                    for (const CommandDef *d = mdef->cmd; d->text; d++)
                        n++;
                }

                {
                    CommandsList it(*cmdsMsg, true);
                    while (++it)
                        n++;
                }
                if (n == 0)
                    return NULL;

                n++;
                CommandDef *cmds = new CommandDef[n];
                memset(cmds, 0, sizeof(CommandDef) * n);
                n = 0;
                if (mdef && mdef->cmd){
                    for (const CommandDef *d = mdef->cmd; d->text; d++){
                        cmds[n] = *d;
                        cmds[n].id = CmdMsgSpecial + n;
                        n++;
                    }
                }
                CommandDef *c;
                CommandsList it(*cmdsMsg, true);
                while ((c = ++it) != NULL){
                    CommandDef cmd = *c;
                    cmd.menu_id = MenuMsgCommand;
                    cmd.param   = msg;
                    Event e(EventCheckState, &cmd);
                    if (!e.process())
                        continue;
                    cmd.flags &= ~COMMAND_CHECK_STATE;
                    cmds[n++] = cmd;
                }
                cmd->param = cmds;
                cmd->flags |= COMMAND_RECURSIVE;
                delete msg;
                return e->param();
            }
            return NULL;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            copy();
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                Event eOpen(EventOpenMessage, msg);
                eOpen.process();
                delete msg;
                return e->param();
            }
            return NULL;
        default:
            msg = currentMessage();
            if (msg){
                if (cmd->id >= CmdMsgSpecial){
                    MessageDef *mdef = NULL;
                    unsigned type = msg->type();
                    for (;;){
                        CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                        if (msgCmd == NULL)
                            break;
                        mdef = (MessageDef*)(msgCmd->param);
                        if (mdef->base_type == 0)
                            break;
                        type = mdef->base_type;
                    }
                    if (mdef && mdef->cmd){
                        unsigned n = cmd->id - CmdMsgSpecial;
                        for (const CommandDef *d = mdef->cmd; d->text; d++){
                            if (n-- == 0){
                                CommandDef cmd = *d;
                                cmd.param = msg;
                                Event eCmd(EventCommandExec, &cmd);
                                eCmd.process();
                                return e->param();
                            }
                        }
                    }
                }
                Command c;
                c->id = cmd->id;
                c->menu_id = MenuMsgCommand;
                c->param = msg;
                Event e(EventCommandExec, c);
                void *res = e.process();
                delete msg;
                return res;
            }
            return NULL;
        }
    }
    return NULL;
}
示例#28
0
void QSAEditor::doObjectCompletion()
{
    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
    QString objectName = cursor.selectedText();
    if (objectName.endsWith(QLatin1Char('-')))
        objectName.chop(1);

    objectName = objectName.simplified();

    QString object = resolveFullyQualifiedValue(objectName, parseAssignments(functionCode()));

    bool assumedStatic = false;
    QSCompletionObject o;
    if(objectName == object) {
        QSObject stobj = env()->globalObject().get(object);
        if(stobj.isValid() && stobj.objectType()->valueType() == TypeClass) {
#if defined ( QSA_COMPLETION_DEBUG )
            printf(" -> assuming static\n");
#endif
            o = stobj;
            assumedStatic = true;
        }
    }
    if(o.type == QSCompletionObject::TNull) {
        o = queryObject(object);
    }

#if defined ( QSA_COMPLETION_DEBUG )
    printf(" -> type is: %d\n", o.type);
#endif

    o.resolve();
    if (o.isNull())
        return;

    QVector<CompletionEntry> res;

    QSObject nullObject;
    switch (o.type) {
    case QSCompletionObject::TQSObject:
#if defined ( QSA_COMPLETION_DEBUG )
        printf(" -> objectType is: %s\n", o.qsobj.objectType()->name().latin1());
#endif
        if(o.qsobj.objectType()->name() == QString::fromLatin1("FactoryObject")){
            QSObject sinst = ( (QSFactoryObjectProxy*) o.qsobj.objectType() )->staticInstance();
            if(!sinst.isValid())
                return;
            QSWrapperShared *shared = (QSWrapperShared*) sinst.shVal();
            completeQObject( shared->objects, object, res );
            break;
        }
        completeQSObject(o.qsobj, res, !assumedStatic);
        break;
    case QSCompletionObject::TQMetaObject:
        completeQMetaObject(o.meta, object, res, IncludeSuperClass, nullObject);
        break;
    case QSCompletionObject::TQObject:
        completeQObject(o.qobj, object, res);
        break;
    case QSCompletionObject::TNull:
        break;
    }

    if (!res.isEmpty()) {
        QFrame *f = new QFrame(0, Qt::Popup);
        f->setAttribute(Qt::WA_DeleteOnClose);

        QWidget *box = new CompletionBox(this, res);

        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(box);
        layout->setMargin(0);
        f->setLayout(layout);

        f->move(mapToGlobal(cursorRect().bottomLeft()));
        f->show();
        box->setFocus();
    }
}
示例#29
0
void Frame::button1Clicked(){
    popup1->move( mapToGlobal( button1->geometry().bottomLeft() ) );
    popup1->show();
}
示例#30
0
void PiecesTable::mousePressEvent(TQMouseEvent* e)
{
    QtTableView::mousePressEvent(e);

    if (e->button() == Qt::RightButton) {
        // execute RMB popup and check result
        _menu->exec(mapToGlobal(e->pos()));
        e->accept();
        return;
    }
    else {
        // GAME LOGIC

        // find the free position
        int pos = _map.find(15);
        if(pos < 0) return;

        int frow = pos / numCols();
        int fcol = pos - frow * numCols();

        // find click position
        int row = findRow(e->y());
        int col = findCol(e->x());

        // sanity check
        if (row < 0 || row >= numRows()) return;
        if (col < 0 || col >= numCols()) return;

        // valid move?
        if(row != frow && col != fcol) return;

        // rows match -> shift pieces
        if(row == frow) {

            if (col < fcol) {
                for(int c = fcol; c > col; c--) {
                    _map[c + row * numCols()] = _map[ c-1 + row *numCols()];
                    updateCell(row, c, false);
                }
            }
            else if (col > fcol) {
                for(int c = fcol; c < col; c++) {
                    _map[c + row * numCols()] = _map[ c+1 + row *numCols()];
                    updateCell(row, c, false);
                }
            }
        }
        // cols match -> shift pieces
        else if (col == fcol) {

            if (row < frow) {
                for(int r = frow; r > row; r--) {
                    _map[col + r * numCols()] = _map[ col + (r-1) *numCols()];
                    updateCell(r, col, false);
                }
            }
            else if (row > frow) {
                for(int r = frow; r < row; r++) {
                    _map[col + r * numCols()] = _map[ col + (r+1) *numCols()];
                    updateCell(r, col, false);
                }
            }
        }
        // move free cell to click position
        _map[col + row * numCols()] = 15;
        updateCell(row, col, false);

        // check if the player wins with this move
        chectwin();
    }
}