Пример #1
0
void HoveringButtonsController::ForwardMouseClickEvent(float x, float y)
{ 
    // To widgetspace
    float x_widgetspace = x*(float)this->width();
    float y_widgetspace = y*(float)this->height();
    QPoint pos(x_widgetspace,y_widgetspace);

    QMouseEvent e(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    QApplication::sendEvent(this, &e);
    
    // Iterate through buttons and check if they are pressed 
    for(int i = 0; i< layout()->count();i++)
    {
        QLayoutItem* item = layout()->itemAt(i);
        QAbstractButton *button = dynamic_cast<QAbstractButton*>(item->widget());
        if(button)
        {
            if(button->rect().contains(button->mapFromParent(pos)))
            {
                QMouseEvent e(QEvent::MouseButtonPress, pos - button->pos(),pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                QApplication::sendEvent(button, &e);
            }
        }
    }
}
Пример #2
0
MyTable::MyTable(QWidget* parent)
    : QTableView(/*RowCount, ColumnCount, */ parent)
    , m_header(new MyHeader(Qt::Vertical, this))
    , m_model(new MyTableModel(this))
#ifdef EXCEL
    , excel(new Excel::Application(this))
#endif
{
    setModel(m_model);
    setVerticalHeader(m_header);

    connect(m_model, &MyTableModel::dataChanged, [=](const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/, const QVector<int>& /*roles*/) {
        updatePlot(topLeft.row());
        resizeRowToContents(topLeft.row());
    });

    QAbstractButton* cornerButton = findChild<QAbstractButton*>();
    if (cornerButton) {
        c = new QCheckBox("№", cornerButton);
        c->setGeometry(cornerButton->rect() + QMargins(-5, 0, 100, 0));
        connect(c, &QCheckBox::toggled, [this](bool checked) { m_header->setChecked(checked); });
    }

    connect(m_header, &MyHeader::checkedChanged, m_model, &MyTableModel::setRowsEnabled);

    setColumnHidden(MeasureDeltaCh0, true);
    setColumnHidden(MeasureDeltaCh1, true);

    horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    horizontalHeader()->setSectionResizeMode(MeasureCh0, QHeaderView::Stretch);
    horizontalHeader()->setSectionResizeMode(MeasureCh1, QHeaderView::Stretch);

    setIconSize(QSize(24, 24));
#ifdef EXCEL
    excel->SetVisible(true);
#endif
}
Пример #3
0
void QAbstractButtonPrivate::moveFocus(int key)
{
    QList<QAbstractButton *> buttonList = queryButtonList();;
#ifndef QT_NO_BUTTONGROUP
    bool exclusive = group ? group->d_func()->exclusive : autoExclusive;
#else
    bool exclusive = autoExclusive;
#endif
    QWidget *f = QApplication::focusWidget();
    QAbstractButton *fb = qobject_cast<QAbstractButton *>(f);
    if (!fb || !buttonList.contains(fb))
        return;

    QAbstractButton *candidate = 0;
    int bestScore = -1;
    QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0)));
    QPoint goal = target.center();
    uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;

    for (int i = 0; i < buttonList.count(); ++i) {
        QAbstractButton *button = buttonList.at(i);
        if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() &&
                (autoExclusive || (button->focusPolicy() & focus_flag) == focus_flag)) {
            QRect buttonRect = button->rect().translated(button->mapToGlobal(QPoint(0,0)));
            QPoint p = buttonRect.center();

            //Priority to widgets that overlap on the same coordinate.
            //In that case, the distance in the direction will be used as significant score,
            //take also in account orthogonal distance in case two widget are in the same distance.
            int score;
            if ((buttonRect.x() < target.right() && target.x() < buttonRect.right())
                    && (key == Qt::Key_Up || key == Qt::Key_Down)) {
                //one item's is at the vertical of the other
                score = (qAbs(p.y() - goal.y()) << 16) + qAbs(p.x() - goal.x());
            } else if ((buttonRect.y() < target.bottom() && target.y() < buttonRect.bottom())
                       && (key == Qt::Key_Left || key == Qt::Key_Right) ) {
                //one item's is at the horizontal of the other
                score = (qAbs(p.x() - goal.x()) << 16) + qAbs(p.y() - goal.y());
            } else {
                score = (1 << 30) + (p.y() - goal.y()) * (p.y() - goal.y()) + (p.x() - goal.x()) * (p.x() - goal.x());
            }

            if (score > bestScore && candidate)
                continue;

            switch(key) {
            case Qt::Key_Up:
                if (p.y() < goal.y()) {
                    candidate = button;
                    bestScore = score;
                }
                break;
            case Qt::Key_Down:
                if (p.y() > goal.y()) {
                    candidate = button;
                    bestScore = score;
                }
                break;
            case Qt::Key_Left:
                if (p.x() < goal.x()) {
                    candidate = button;
                    bestScore = score;
                }
                break;
            case Qt::Key_Right:
                if (p.x() > goal.x()) {
                    candidate = button;
                    bestScore = score;
                }
                break;
            }
        }
    }

    if (exclusive
#ifdef QT_KEYPAD_NAVIGATION
            && !QApplication::keypadNavigationEnabled()
#endif
            && candidate
            && fb->d_func()->checked
            && candidate->d_func()->checkable)
        candidate->click();

    if (candidate) {
        if (key == Qt::Key_Up || key == Qt::Key_Left)
            candidate->setFocus(Qt::BacktabFocusReason);
        else
            candidate->setFocus(Qt::TabFocusReason);
    }
}