Ejemplo n.º 1
0
void OutputWidget::activate(const QModelIndex& index)
{
    auto iface = outputViewModel();
    auto view = outputView();
    if( ! view || ! iface )
        return;
    activateIndex(index, view, iface);
}
Ejemplo n.º 2
0
void OutputWidget::selectItem(SelectionMode selectionMode)
{
    auto view = outputView();
    auto iface = outputViewModel();
    if ( ! view || ! iface )
        return;
    eventuallyDoFocus();

    auto index = view->currentIndex();

    if (QAbstractProxyModel* proxy = proxyModels.value(currentOutputIndex())) {
        if ( index.model() == proxy ) {
            // index is from the proxy, map it to the source
            index = proxy->mapToSource(index);
        }
    }

    QModelIndex newIndex;
    switch (selectionMode) {
        case First:
            newIndex = iface->firstHighlightIndex();
            break;
        case Next:
            newIndex = iface->nextHighlightIndex( index );
            break;
        case Previous:
            newIndex = iface->previousHighlightIndex( index );
            break;
        case Last:
            newIndex = iface->lastHighlightIndex();
            break;
    }

    qCDebug(PLUGIN_STANDARDOUTPUTVIEW) << "old:" << index << "- new:" << newIndex;
    activateIndex(newIndex, view, iface);
}
Ejemplo n.º 3
0
//Setup the GUI
NameList::NameList(QWidget *parent) :
    QWidget(parent)
{
    //Main layout
    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    //Horizontal layout for the title and button
    QHBoxLayout *hLayout = new QHBoxLayout();
    hLayout->setStretch(0,1);
    mainLayout->addLayout(hLayout);

    //Title (empty)
    _title = new QLabel();
    hLayout->addWidget(_title);

    //Spacer
    QSpacerItem *spacer = new QSpacerItem(0,0);
    hLayout->addSpacerItem(spacer);
    hLayout->setStretch(1,1);

    //Buttons
    b_load = new QToolButton();
    b_load->setIcon(QIcon(":/images/open.png"));
    b_load->setToolTip(QString("Load existing"));
    b_up = new QToolButton();
    b_up->setIcon(QIcon::fromTheme("go-up",QIcon(":images/up.png")));
    b_down = new QToolButton();
    b_down->setIcon(QIcon::fromTheme("go-down",QIcon(":images/down.png")));
    b_add = new QToolButton();
    b_add->setIcon(QIcon::fromTheme("list-add",QIcon(":images/add.png")));
    b_add->setToolTip(QString("Add new"));
    b_remove = new QToolButton();
    b_remove->setIcon(QIcon::fromTheme("list-remove",QIcon(":images/delete.png")));
    b_remove->setToolTip(QString("Remove"));
    hLayout->addWidget(b_up);
    hLayout->addWidget(b_down);
    hLayout->addWidget(b_load);
    hLayout->addWidget(b_add);
    hLayout->addWidget(b_remove);

    //The list and its model
    _table = new QTableWidget();
    _table->setColumnCount(1);
    _table->horizontalHeader()->setSectionResizeMode(0,QHeaderView::Stretch);
    _table->horizontalHeader()->hide();
    _table->verticalHeader()->hide();
    _table->setSelectionBehavior(QAbstractItemView::SelectRows);
    _table->setMinimumHeight(100);

    mainLayout->addWidget(_table);

    //Connect the buttons
    CONNECT(b_up, SIGNAL(clicked()), this, SLOT(up()));
    CONNECT(b_down, SIGNAL(clicked()), this, SLOT(down()));
    CONNECT(b_load, SIGNAL(clicked()), this, SIGNAL(loadClicked()));
    CONNECT(b_add, SIGNAL(clicked()), this, SIGNAL(addClicked()));
    CONNECT(b_remove, SIGNAL(clicked()), this, SLOT(removeCurrent()));

    //Enable/disables the buttons
    CONNECT(this, SIGNAL(appened(void*)), this, SLOT(checkSize()));
    CONNECT(this, SIGNAL(removed(void*)), this, SLOT(checkSize()));
    CONNECT(this, SIGNAL(appened(void*)), this, SLOT(checkUpDown()));
    CONNECT(this, SIGNAL(removed(void*)), this, SLOT(checkUpDown()));
    CONNECT(_table, SIGNAL(clicked(QModelIndex)), this, SLOT(checkUpDown()));
    CONNECT(_table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(checkUpDown()));

    //Redirect list signals
    CONNECT(_table, SIGNAL(activated(QModelIndex)), this, SLOT(activateIndex(QModelIndex)));
    CONNECT(_table, SIGNAL(clicked(QModelIndex)), this, SLOT(selectIndex(QModelIndex)));

    //By default, do not show all buttons
    hideUpDown(true);
//    hideLoad(true);
    hideAdd(true);
    //And they are disabled
    b_up->setEnabled(false);
    b_down->setEnabled(false);
    //The remove button too
    b_remove->setEnabled(false);

    //Lower our minimal height and change our vertical policy
    this->setMinimumHeight(100);
    this->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding);
}