Ejemplo n.º 1
0
void QmlConsoleView::contextMenuEvent(QContextMenuEvent *event)
{
    QModelIndex itemIndex = indexAt(event->pos());
    QMenu menu;

    QAction *copy = new QAction(tr("&Copy"), this);
    copy->setEnabled(itemIndex.isValid());
    menu.addAction(copy);
    QAction *show = new QAction(tr("&Show in Editor"), this);
    show->setEnabled(canShowItemInTextEditor(itemIndex));
    menu.addAction(show);
    menu.addSeparator();
    QAction *clear = new QAction(tr("C&lear"), this);
    menu.addAction(clear);

    QAction *a = menu.exec(event->globalPos());
    if (a == 0)
        return;

    if (a == copy) {
        copyToClipboard(itemIndex);
    } else if (a == show) {
        onRowActivated(itemIndex);
    } else if (a == clear) {
        QAbstractProxyModel *proxyModel = qobject_cast<QAbstractProxyModel *>(model());
        QmlConsoleItemModel *handler = qobject_cast<QmlConsoleItemModel *>(
                    proxyModel->sourceModel());
        handler->clear();
    }
}
Ejemplo n.º 2
0
Main::Main()
    : QMainWindow()
{
    QWidget *main = new QWidget (this);
    setCentralWidget(main);
    QVBoxLayout *layout = new QVBoxLayout;
    QListView *all = new QListView;
    all->setModelColumn(UPnPDeviceModel::DeviceRoleFriendlyName);
    all->setModel(UPnPDeviceModel::getDefault());
    QListView *server = new QListView;
    server->setModel(new UPnPServerModel ());
    server->setModelColumn(UPnPDeviceModel::DeviceRoleFriendlyName);
    connect (server, SIGNAL(activated(QModelIndex)), SLOT(onRowActivated(QModelIndex)));
    QListView *renderer = new QListView;
    renderer->setModel(new UPnPRendererModel ());
    renderer->setModelColumn(UPnPDeviceModel::DeviceRoleFriendlyName);
    m_browser = new QListView;

    layout->addWidget(new QLabel(QString::fromLatin1("All devices"), main));
    layout->addWidget(all);
    layout->addWidget(new QLabel(QString::fromLatin1("UPnP servers"), main));
    layout->addWidget(server);
    layout->addWidget(new QLabel(QString::fromLatin1("UPnP renderer"), main));
    layout->addWidget(renderer);
    layout->addWidget(new QLabel(QLatin1String("Browse test"), main));
    layout->addWidget(m_browser);
    main->setLayout(layout);
}
Ejemplo n.º 3
0
QmlConsoleView::QmlConsoleView(QWidget *parent) :
    Utils::TreeView(parent)
{
    setFrameStyle(QFrame::NoFrame);
    setHeaderHidden(true);
    setRootIsDecorated(false);
    setUniformRowHeights(true);
    setEditTriggers(QAbstractItemView::AllEditTriggers);
    setStyleSheet(QLatin1String("QTreeView::branch:has-siblings:!adjoins-item {"
                                "border-image: none;"
                                "image: none; }"
                                "QTreeView::branch:has-siblings:adjoins-item {"
                                "border-image: none;"
                                "image: none; }"
                                "QTreeView::branch:!has-children:!has-siblings:adjoins-item {"
                                "border-image: none;"
                                "image: none; }"
                                "QTreeView::branch:has-children:!has-siblings:closed,"
                                "QTreeView::branch:closed:has-children:has-siblings {"
                                "border-image: none;"
                                "image: none; }"
                                "QTreeView::branch:open:has-children:!has-siblings,"
                                "QTreeView::branch:open:has-children:has-siblings  {"
                                "border-image: none;"
                                "image: none; }"));

    QString baseName = QApplication::style()->objectName();
    if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost()
            && baseName == QLatin1String("windows")) {
        // Sometimes we get the standard windows 95 style as a fallback
        if (QStyleFactory::keys().contains(QLatin1String("Fusion"))) {
            baseName = QLatin1String("fusion"); // Qt5
        } else { // Qt4
            // e.g. if we are running on a KDE4 desktop
            QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION");
            if (desktopEnvironment == "kde")
                baseName = QLatin1String("plastique");
            else
                baseName = QLatin1String("cleanlooks");
        }
    }
    QmlConsoleViewStyle *style = new QmlConsoleViewStyle(baseName);
    setStyle(style);
    style->setParent(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
    horizontalScrollBar()->setSingleStep(20);
    verticalScrollBar()->setSingleStep(20);

    connect(this, SIGNAL(activated(QModelIndex)), SLOT(onRowActivated(QModelIndex)));
}