pynoto / src / Main / ConsoleWidget.cpp

#include <QDebug>
#include <QTableView>

#include "Consoles/IssuesConsole.h"
#include "Consoles/ApplicationConsole.h"
#include "Consoles/LogConsole.h"
#include "Include/PynotoApplication.h"
#include "Include/IIconProvider.h"
#include "ConsoleWidget.h"
#include "ui_ConsoleWidget.h"

namespace Main {

ConsoleWidget::ConsoleWidget(QWidget *parent):
    QWidget(parent),
    _ui(new Ui::ConsoleWidget),
    _issues(new IssuesConsole(this)),
    _application(new ApplicationConsole(this)),
    _log(new LogConsole(this)),
    _mode(-1)
{
    _ui->setupUi(this);
    _ui->stack->setFrameStyle(QFrame::NoFrame);
    _ui->modes->addItem(tr("Issues"));
    _ui->modes->addItem(tr("Application output"));
    _ui->modes->addItem(tr("Search result"));
    _ui->modes->addItem(tr("System log"));

    _ui->hideBtn->setIcon(Aux::icons()->icon("hide"));
    connect(_ui->hideBtn, SIGNAL(clicked()), SLOT(hide()));
    connect(_ui->modes, SIGNAL(currentIndexChanged(int)), SLOT(switchTo(int)));

    _ui->stack->addWidget(_issues->control());
    _ui->stack->addWidget(_application->control());
    _ui->stack->addWidget(new QWidget(this));
    _ui->stack->addWidget(_log->control());
    setVisible(false);
}

ConsoleWidget::~ConsoleWidget()
{
    delete _ui;
}

IssuesConsole * ConsoleWidget::issues()
{
    return _issues;
}

void ConsoleWidget::setup(EditorsManager::IEditorsManagerPlugin* editors, QButtonGroup * btns)
{
    _buttonGroup = btns;
    connect(editors, SIGNAL(errorListChanged(QAbstractTableModel*)), SLOT(errorListChanged(QAbstractTableModel*)));
    connect(_issues, SIGNAL(refresh()), editors, SLOT(checkIssues()));
    connect(_issues, SIGNAL(activated(int)), editors, SLOT(jumpCurrentFileLine(int)));
}


void ConsoleWidget::errorListChanged(QAbstractTableModel* model)
{
    _buttonGroup->button(0)->setText(model && model->rowCount() ? tr("Issues (%1)").arg(model->rowCount()) : tr("Issues"));
    _issues->setModel(model);
    switchTo(0);
}

void ConsoleWidget::switchTo(int mode)
{
    if (mode != _mode){
        _ui->modes->blockSignals(true);
        _ui->modes->setCurrentIndex(mode);
        _ui->modes->blockSignals(false);
        _ui->stack->setCurrentIndex(mode);

        QLayoutItem * item;
        do {
            item = _ui->headerPlace->layout()->takeAt(0);
            if (item){
                _ui->headerPlace->layout()->removeWidget(item->widget());
                item->widget()->hide();
                delete item;
            }
        } while (item);

        if (mode == 0){
            _ui->headerPlace->layout()->addWidget(_issues->header());
            _issues->header()->show();
        } else if (mode == 1) {
            _ui->headerPlace->layout()->addWidget(_application->header());
            _application->header()->show();
        } else if (mode == 3) {
            _ui->headerPlace->layout()->addWidget(_log->header());
            _log->header()->show();
        }

        _mode = mode;
        emit consoleChanged(mode);
    }
    setVisible(true);
}

/*void BottomDockWidget::modeSelected(DockShowMode mode)
{
    if (mode == Show){
        show();
    }
    if (mode == Hide){
        hide();
    }
    if (mode == ShowRun){
        emit dockModeSelected(ShowRun);
        setCurrentIndex(0);
        show();
    }
    if (mode == ShowSearch){
        emit dockModeSelected(ShowSearch);
        setCurrentIndex(1);
        show();
    }
    if (mode == ShowErrors){
        emit dockModeSelected(ShowErrors);
        setCurrentIndex(2);
        show();
    }
}


Console * BottomDockWidget::console()
{
    return _console;
}

QWidget * BottomDockWidget::consoleWindow()
{
    return _console;
}

void BottomDockWidget::filesFound(const QStringList& list)
{
    _search->setResult(list);
    modeSelected(ShowSearch);
}*/

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.