int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QDirModel model;

    QTreeView tree;
    QListView list;
    QTableView table;

    tree.setModel(&model);
    list.setModel(&model);
    table.setModel(&model);

    tree.setSelectionMode(QAbstractItemView::MultiSelection);
    list.setSelectionModel(tree.selectionModel());
    table.setSelectionModel(tree.selectionModel());

    QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&list,SLOT(setRootIndex(QModelIndex)));
    QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&table,SLOT(setRootIndex(QModelIndex)));

    QSplitter *splitter = new QSplitter;
    splitter->addWidget(&tree);
    splitter->addWidget(&list);
    splitter->addWidget(&table);
    splitter->setWindowTitle(QObject::tr("Model/View"));
    splitter->show();
    
    return a.exec();
}
Example #2
0
int main( int argc, char **argv )
{
    QApplication app( argc, argv );

    QTreeView *tree = new QTreeView();
    QListView *list = new QListView();
    QTableView *table = new QTableView();

    QSplitter splitter;
    splitter.addWidget(tree);
    splitter.addWidget(list);
    splitter.addWidget(table);

    QStandardItemModel model( 5, 2 );

    for( int r=0; r<5; r++ )
    {
        for( int c=0; c<2; c++)
        {
            QStandardItem *item = new QStandardItem(QString("Row:%0, Column:%1").arg(r).arg(c));

            if(c == 0)
            {
                for(int i=0; i<3; i++)
                {
                    QStandardItem *child = new QStandardItem(QString("Item %0").arg(i));
                    child->setEditable(false);
                    item->appendRow(child);
                }
            }

            model.setItem(r, c, item);
        }
    }

    model.setHorizontalHeaderItem(0, new QStandardItem("Foo"));
    model.setHorizontalHeaderItem(1, new QStandardItem("Bar-Baz"));

    tree->setModel(&model);
    list->setModel(&model);
    table->setModel(&model);

    list->setSelectionModel(tree->selectionModel());
    table->setSelectionModel(tree->selectionModel());

    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->setSelectionMode(QAbstractItemView::SingleSelection);

    splitter.show();

    MainWindow w;
    w.show();

    return app.exec();
}
Example #3
0
ctkDICOMHostMainLogic::ctkDICOMHostMainLogic(ctkHostedAppPlaceholderWidget* placeHolder, ctkDICOMAppWidget* dicomAppWidget, 
                                             QWidget* placeHolderForControls) : 
  QObject(placeHolder), 
  PlaceHolderForHostedApp(placeHolder),
  DicomAppWidget(dicomAppWidget),
  PlaceHolderForControls(placeHolderForControls),
  ValidSelection(false),
  SendData(false)
{
  this->Host = new ctkExampleDicomHost(PlaceHolderForHostedApp);
  this->HostControls = new ctkExampleHostControlWidget(Host, PlaceHolderForControls);

  Data = new ctkDicomAppHosting::AvailableData;

  disconnect(this->Host,SIGNAL(startProgress()),this->Host,SLOT(onStartProgress()));
  connect(this->Host,SIGNAL(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection);
  connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData()), Qt::QueuedConnection);
  connect(this->PlaceHolderForHostedApp,SIGNAL(resized()),this,SLOT(placeHolderResized()));

  QTreeView * treeview = dicomAppWidget->findChild<QTreeView*>("TreeView");
  QItemSelectionModel* selectionmodel = treeview->selectionModel();
  connect(selectionmodel, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
    this, SLOT(onTreeSelectionChanged(const QItemSelection &, const QItemSelection &)));

  connect(this->Host, SIGNAL(dataAvailable()), this, SLOT(onDataAvailable()));

  connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()) );
}
Example #4
0
LessThanWidget::LessThanWidget(QWidget* parent, Qt::WindowFlags f)
    : QWidget(parent, f)
{
  QLabel *explanation = new QLabel(this);
  explanation->setText("The yellow items are 'less than' the selected item according to QModelIndex::operator<().\n"
                       "The red items are greater than the selected item (i.e, not less than and not equal).");

  m_coloredTreeModel = new ColoredTreeModel(this);
  QTreeView *treeView = new QTreeView(this);
  treeView->setModel(m_coloredTreeModel);
  treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
  treeView->setSelectionMode(QTreeView::SingleSelection);

  m_coloredTreeModel->setSelectionModel(treeView->selectionModel());

  QVBoxLayout *layout = new QVBoxLayout(this);
  layout->addWidget(explanation);
  layout->addWidget(treeView);

  insertGrid(QList<int>());
  insertGrid(QList<int>() << 2);
  insertGrid(QList<int>() << 3);
  insertGrid(QList<int>() << 4);
  insertGrid(QList<int>() << 3 << 2);
  insertGrid(QList<int>() << 3 << 3);
  insertGrid(QList<int>() << 3 << 4);
}
GraphViewer::GraphViewer(ProbeInterface *probe, QWidget *parent)
    : QWidget(parent),
      mWidget(new GraphWidget(this)),
      mProbeIface(probe)
{
    QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this);
    objectFilter->setSourceModel(probe->objectTreeModel());
    objectFilter->setDynamicSortFilter(true);

    QVBoxLayout *vbox = new QVBoxLayout;
    KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this);
    objectSearchLine->setProxy(objectFilter);
    vbox->addWidget(objectSearchLine);
    QTreeView *objectTreeView = new QTreeView(this);
    objectTreeView->setModel(objectFilter);
    objectTreeView->setSortingEnabled(true);
    vbox->addWidget(objectTreeView);
    connect(objectTreeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
            SLOT(handleRowChanged(QModelIndex)));
    mObjectTreeView = objectTreeView;

    QWidget *treeViewWidget = new QWidget(this);
    treeViewWidget->setLayout(vbox);

    QSplitter *splitter = new QSplitter(this);
    splitter->addWidget(treeViewWidget);
    splitter->addWidget(mWidget);
    QHBoxLayout *hbox = new QHBoxLayout(this);
    hbox->addWidget(splitter);

    QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection);
}
Example #6
0
// ------------ ObjectInspector
ObjectInspector::ObjectInspector(QDesignerFormEditorInterface *core, QWidget *parent) :
    QDesignerObjectInspector(parent),
    m_impl(new ObjectInspectorPrivate(core))
{
    QVBoxLayout *vbox = new QVBoxLayout(this);
    vbox->setMargin(0);

    QTreeView *treeView = m_impl->treeView();
    vbox->addWidget(treeView);

    connect(treeView, SIGNAL(customContextMenuRequested(QPoint)),
            this, SLOT(slotPopupContextMenu(QPoint)));

    connect(treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)));

    connect(treeView->header(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(slotHeaderDoubleClicked(int)));
    setAcceptDrops(true);

    ItemViewFindWidget *findWidget = m_impl->findWidget();
    vbox->addWidget(findWidget);

    findWidget->setItemView(treeView);
    QAction *findAction = new QAction(
            ItemViewFindWidget::findIconSet(),
            tr("&Find in Text..."),
            this);
    findAction->setShortcut(QKeySequence::Find);
    findAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
    addAction(findAction);
    connect(findAction, SIGNAL(triggered(bool)), findWidget, SLOT(activate()));
}
Example #7
0
void TabWidget::updateActions()
{
    QTreeView *view = m_ui->treeView;
    bool hasSelection = !view->selectionModel()->selection().isEmpty();
    //removeRowAction->setEnabled(hasSelection);
    //removeColumnAction->setEnabled(hasSelection);

    bool hasCurrent = view->selectionModel()->currentIndex().isValid();
    //insertRowAction->setEnabled(hasCurrent);
    //insertColumnAction->setEnabled(hasCurrent);

    if (hasCurrent) {
        view->closePersistentEditor(view->selectionModel()->currentIndex());

        int row = view->selectionModel()->currentIndex().row();
        int column = view->selectionModel()->currentIndex().column();
    }

}
Example #8
0
	QSslCertificate ManagerDialog::GetSelectedCert (CertPart part) const
	{
		QTreeView *view = nullptr;
		switch (part)
		{
		case CertPart::System:
			view = Ui_.SystemTree_;
			break;
		case CertPart::Local:
			view = Ui_.LocalTree_;
			break;
		}

		if (!view)
			return {};

		const auto& selected = view->selectionModel ()->selectedRows ();
		return selected.value (0).data (CertsModel::CertificateRole).value<QSslCertificate> ();
	}
void Test_FileSystem_MVC()
{
	QSplitter* splitter = new QSplitter;//two widget
	QFileSystemModel* model = new QFileSystemModel;
	QTreeView* tree = new QTreeView(splitter);//left tree view
	QListView* list = new QListView(splitter);//right list view

	splitter->setWindowTitle("Two vies onto the same file system model");

	model->setRootPath(QDir::currentPath());
	tree->setModel(model);//set model for view
	tree->setRootIndex(model->index(QDir::currentPath()));

	list->setModel(model);
	list->setRootIndex(model->index(QDir::currentPath()));

	list->setSelectionModel(tree->selectionModel());
	splitter->show();

}
Example #10
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    qRegisterMetaType<Error>();

    ThreadedParser parser;

    Memcheck::MemcheckRunner runner;
    runner.setValgrindExecutable(fakeValgrindExecutable());
    runner.setValgrindArguments(QStringList() << QLatin1String("-i") << dataFile(QLatin1String("memcheck-output-sample1.xml")) );
    runner.setParser(&parser);

    ModelDemo demo(&runner);
    QObject::connect(&runner, &ValgrindRunner::finished,
                     &demo, &ModelDemo::finished);
    ErrorListModel model;
    QObject::connect(&parser, &ThreadedParser::error,
                     &model, &ErrorListModel::addError,
                     Qt::QueuedConnection);

    QTreeView errorview;
    errorview.setSelectionMode(QAbstractItemView::SingleSelection);
    errorview.setSelectionBehavior(QAbstractItemView::SelectRows);
    errorview.setModel(&model);
    errorview.show();

    StackModel stackModel;
    demo.stackModel = &stackModel;

    QTreeView stackView;
    stackView.setModel(&stackModel);
    stackView.show();

    QObject::connect(errorview.selectionModel(), &QItemSelectionModel::selectionChanged,
                     &demo, &ModelDemo::selectionChanged);


    runner.start();

    return app.exec();
}
Example #11
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    qRegisterMetaType<Valgrind::XmlProtocol::Error>();

    ThreadedParser parser;

    Valgrind::Memcheck::MemcheckRunner runner;
    runner.setValgrindExecutable(fakeValgrindExecutable());
    runner.setValgrindArguments(QStringList() << QLatin1String("-i") << dataFile(QLatin1String("memcheck-output-sample1.xml")) );
    runner.setParser(&parser);

    ModelDemo demo(&runner);
    runner.connect(&runner, SIGNAL(finished()), &demo, SLOT(finished()));
    ErrorListModel model;
    parser.connect(&parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
                   &model, SLOT(addError(Valgrind::XmlProtocol::Error)),
                   Qt::QueuedConnection);

    QTreeView errorview;
    errorview.setSelectionMode(QAbstractItemView::SingleSelection);
    errorview.setSelectionBehavior(QAbstractItemView::SelectRows);
    errorview.setModel(&model);
    errorview.show();

    StackModel stackModel;
    demo.stackModel = &stackModel;

    QTreeView stackView;
    stackView.setModel(&stackModel);
    stackView.show();

    errorview.connect(errorview.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                      &demo, SLOT(selectionChanged(QItemSelection,QItemSelection)));


    runner.start();

    return app.exec();
}
Example #12
0
void MainWindow::loadPlaylists()
{
    QTreeView *playlists = (QTreeView*)ui->tvPlaylists;

    QStandardItemModel *model = new QStandardItemModel(3,1);
    QStandardItem *item = new QStandardItem(QString(tr("Search")));
    item->setData(DATA_SEARCH, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    model->setItem(0, 0, item);
    item = new QStandardItem(QString(tr("History")));
    item->setData(DATA_HISTORY, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    model->setItem(1, 0, item);
    item = new QStandardItem(QString(tr("Playlists")));
    item->setData(DATA_EMPTY, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    QList<Playlist> pls = dp->getPlaylists();
    int n = pls.count();
    for( int i=0; i<n; i++ )
    {
      QStandardItem *child = new QStandardItem(pls[i].title);
      child->setData(pls[i].id, DATA_KEY_PLAYLIST);
      child->setEditable(false);
      item->appendRow(child);
    }
    model->setItem(2, 0, item);
    model->setHorizontalHeaderItem( 0, new QStandardItem(tr("Library")));
    model->horizontalHeaderItem(0)->setEditable(false);
    model->horizontalHeaderItem(0)->setEnabled(false);

    playlists->setModel(model);
    playlists->setContextMenuPolicy(Qt::CustomContextMenu);

    QModelIndexList indexes = model->match(model->index(2,0), Qt::DisplayRole, "*", -1, Qt::MatchWildcard|Qt::MatchRecursive);
    playlists->expand(indexes[0]);

    connect(playlists->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(loadPlaylist()));
}
Example #13
0
void TestGlobalSearch::testGlobalSearch()
{
    QString filename(QFile::decodeName(FILES_DATA_DIR "/TestGlobalSearch.kexi"));
    kDebug() << filename;
    NewArgs args(m_argv);
    args.vals[args.count - 1] = qstrdup(QFile::encodeName(filename).constData());

    KexiAboutData aboutData;
    aboutData.setProgramName(ki18n(metaObject()->className()));
    int result = KexiMainWindow::create(args.count, args.vals, aboutData);
    QVERIFY(kapp);
    QCOMPARE(result, 0);

    QLineEdit *lineEdit = kexiTester().widget<QLineEdit*>("globalSearch.lineEdit");
    QVERIFY(lineEdit);
    QTreeView *treeView = kexiTester().widget<QTreeView*>("globalSearch.treeView");
    QVERIFY(treeView);

    lineEdit->setFocus();
    // enter "cars", expect 4 completion items
    QTest::keyClicks(lineEdit, "cars");
    QVERIFY(treeView->isVisible());
    int globalSearchCompletionListRows = treeView->model()->rowCount();
    QCOMPARE(globalSearchCompletionListRows, 4);

    // add "x", expect no completion items and hidden list
    QTest::keyClicks(lineEdit, "x");
    QVERIFY(!treeView->isVisible());
    globalSearchCompletionListRows = treeView->model()->rowCount();
    QCOMPARE(globalSearchCompletionListRows, 0);

    // Escape should clear
    QTest::keyClick(lineEdit, Qt::Key_Escape,  Qt::NoModifier, GUI_DELAY);
    QVERIFY(lineEdit->text().isEmpty());

    QTest::keyClicks(lineEdit, "cars");
    QVERIFY(treeView->isVisible());
    treeView->setFocus();
    QTest::keyPress(treeView, Qt::Key_Down, Qt::NoModifier, GUI_DELAY);
    QTest::keyPress(treeView, Qt::Key_Down, Qt::NoModifier, GUI_DELAY);
    QTest::keyPress(treeView, Qt::Key_Down, Qt::NoModifier, GUI_DELAY);

    // 3rd row should be "cars" form
    QModelIndexList selectedIndices = treeView->selectionModel()->selectedRows();
    QCOMPARE(selectedIndices.count(), 1);
    QCOMPARE(treeView->model()->data(selectedIndices.first(), Qt::DisplayRole).toString(), QLatin1String("cars"));

    // check if proper entry of Project Navigator is selected
    QTest::keyPress(treeView, Qt::Key_Enter, Qt::NoModifier, GUI_DELAY);

    KexiProjectNavigator *projectNavigator = kexiTester().widget<KexiProjectNavigator*>("KexiProjectNavigator");
    QVERIFY(projectNavigator);
    KexiPart::Item* selectedPartItem = projectNavigator->selectedPartItem();
    QVERIFY(selectedPartItem);
    QCOMPARE(selectedPartItem->name(), QLatin1String("cars"));
    QCOMPARE(selectedPartItem->partClass(), QLatin1String("org.kexi-project.form"));

    if (m_goToEventLoop) {
        result = qApp->exec();
        QCOMPARE(result, 0);
    }
}
Example #14
0
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
	: QDialog(parent), predefinedTokens(_predefinedTokens)
{
	nameLabel = new QLabel(tr("&Name:"));
	nameEdit = new QLineEdit(tr("Token"));
	nameEdit->selectAll();
	nameLabel->setBuddy(nameEdit);

	colorLabel = new QLabel(tr("C&olor:"));
	colorEdit = new QComboBox;
	colorEdit->addItem(tr("white"), "w");
	colorEdit->addItem(tr("blue"), "u");
	colorEdit->addItem(tr("black"), "b");
	colorEdit->addItem(tr("red"), "r");
	colorEdit->addItem(tr("green"), "g");
	colorEdit->addItem(tr("multicolor"), "m");
	colorEdit->addItem(tr("colorless"), QString());
	colorLabel->setBuddy(colorEdit);

	ptLabel = new QLabel(tr("&P/T:"));
	ptEdit = new QLineEdit;
	ptLabel->setBuddy(ptEdit);

	annotationLabel = new QLabel(tr("&Annotation:"));
	annotationEdit = new QLineEdit;
	annotationLabel->setBuddy(annotationEdit);
	
	destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
	destroyCheckBox->setChecked(true);

	QGridLayout *grid = new QGridLayout;
	grid->addWidget(nameLabel, 0, 0);
	grid->addWidget(nameEdit, 0, 1);
	grid->addWidget(colorLabel, 1, 0);
	grid->addWidget(colorEdit, 1, 1);
	grid->addWidget(ptLabel, 2, 0);
	grid->addWidget(ptEdit, 2, 1);
	grid->addWidget(annotationLabel, 3, 0);
	grid->addWidget(annotationEdit, 3, 1);
	grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
	
	QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
	tokenDataGroupBox->setLayout(grid);
	
	cardDatabaseModel = new CardDatabaseModel(db, this);
	cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
	cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
	cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
	
	chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
	connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
	chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
	connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
	QTreeView *chooseTokenView = new QTreeView;
	chooseTokenView->setModel(cardDatabaseDisplayModel);
	chooseTokenView->setUniformRowHeights(true);
	chooseTokenView->setRootIsDecorated(false);
	chooseTokenView->setAlternatingRowColors(true);
	chooseTokenView->setSortingEnabled(true);
	chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
	chooseTokenView->resizeColumnToContents(0);
	chooseTokenView->header()->setStretchLastSection(false);
	chooseTokenView->header()->hideSection(1);
	chooseTokenView->header()->hideSection(2);
	chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
	chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
	connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
	
	if (predefinedTokens.isEmpty())
		chooseTokenFromAllRadioButton->setChecked(true);
	else {
		chooseTokenFromDeckRadioButton->setChecked(true);
		cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
	}
	
	QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
	tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
	tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
	tokenChooseLayout->addWidget(chooseTokenView);
	
	QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
	tokenChooseGroupBox->setLayout(tokenChooseLayout);
	
	QVBoxLayout *leftVBox = new QVBoxLayout;
	leftVBox->addWidget(tokenDataGroupBox);
	leftVBox->addStretch();
	
	QHBoxLayout *hbox = new QHBoxLayout;
	hbox->addLayout(leftVBox);
	hbox->addWidget(tokenChooseGroupBox);
	
	QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	
	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addLayout(hbox);
	mainLayout->addWidget(buttonBox);
	setLayout(mainLayout);

	setWindowTitle(tr("Create token"));
	setFixedHeight(sizeHint().height());
	setMinimumWidth(300);
}
Example #15
0
MultiQFileDialog::MultiQFileDialog(QWidget *parent, const QString &caption, const QString &directory, bool multiSelect, const QString &filter)
    : QFileDialog(parent, caption, directory, filter)
{
    this->showHidden = false;
    this->multiSelect = multiSelect;
    setOption(QFileDialog::DontUseNativeDialog, false);

    if (multiSelect)
    {
        setOption(QFileDialog::DontUseNativeDialog, true);
        le = findChild<QLineEdit*>(QString::fromUtf8("fileNameEdit"));

        QListView *l = findChild<QListView*>(QString::fromUtf8("listView"));
        if (l)
        {
            l->setSelectionMode(QListView::ExtendedSelection);
            if (le)
            {
                connect(l->selectionModel(),
                        SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
                        this,
                        SLOT(onSelectionChanged ( const QItemSelection &, const QItemSelection & )));
            }
        }

        QTreeView *t = findChild<QTreeView*>();
        if (t)
        {
            t->setSelectionMode(QAbstractItemView::ExtendedSelection);
            if (le)
            {
                connect(t->selectionModel(),
                        SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
                        this,
                        SLOT(onSelectionChanged ( const QItemSelection &, const QItemSelection & )));
            }
        }

        QLabel *label = findChild<QLabel*>(QString::fromUtf8("fileNameLabel"));
        if (label)
        {
            label->hide();
        }

        label = findChild<QLabel*>(QString::fromUtf8("fileTypeLabel"));
        if (label)
        {
            label->hide();
        }

        label = findChild<QLabel*>(QString::fromUtf8("lookInLabel"));
        if (label)
        {
            label->hide();
        }

        QDialogButtonBox *buttonBox = findChild<QDialogButtonBox*>(QString::fromUtf8("buttonBox"));
        if (buttonBox)
        {
            buttonBox->button(QDialogButtonBox::Open)->setText(QCoreApplication::translate("QDialogButtonBox", "&OK"));
        }

        setFileMode(QFileDialog::ExistingFiles);
        if (le)
        {
            le->setText(QCoreApplication::translate("ShellExtension", "Upload to MEGA"));
        }
    }

    QList<QWidget *> widgets = findChildren<QWidget *>();
    for (QList<QWidget *>::const_iterator it = widgets.begin(); it != widgets.end(); ++it)
    {
       (*it)->installEventFilter(this);
    }
    installEventFilter(this);
}
SelectionProxyWidget::SelectionProxyWidget(QWidget *parent): QWidget(parent)
{
    QHBoxLayout *layout = new QHBoxLayout(this);
    QSplitter *splitter = new QSplitter(this);
    layout->addWidget(splitter);

    m_rootModel = new DynamicTreeModel(this);

    DynamicTreeWidget *dynTreeWidget = new DynamicTreeWidget(m_rootModel, splitter);

    dynTreeWidget->setInitialTree(
        QLatin1String("- 1"
        "- 2"
        "- - 3"
        "- - 3"
        "- - - 4"
        "- - - 4"
        "- - - - 4"
        "- - 4"
        "- - 5"
        "- - - 4"
        "- - - - 4"
        "- - 5"
        "- 6"
        "- 7"
        "- - 8"
        "- - - 9"
        "- - - 10"
        "- - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - - - - 9"
        "- - - - - - - - 10"
        "- - - - - - - - 9"
        "- - - - - - - 10"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - 10"
        "- - 11"
        "- - 12"
        "- 13"
        "- 14"
        "- 15"
        "- - 16"
        "- - - 17"
        "- - - 18"
        "- 19"
        "- 20"
        "- 21"));

    QTreeView *selectionTree = createLabelledView(QStringLiteral("Selection"), splitter);
    selectionTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
    selectionTree->setModel(m_rootModel);
    selectionTree->expandAll();

#define SUBTREES
#define SUBTREEROOTS
#define SUBTREESWITHOUTROOTS
#define EXACTSELECTION
#define CHILDRENOFEXACTSELECTION

#ifdef SUBTREES
    KSelectionProxyModel *selectedBranchesModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesModel->setSourceModel(m_rootModel);
    selectedBranchesModel->setFilterBehavior(KSelectionProxyModel::SubTrees);

    QTreeView *selectedBranchesView = createLabelledView(QStringLiteral("SubTrees"), splitter);
    selectedBranchesView->setModel(selectedBranchesModel);
#endif

#ifdef SUBTREEROOTS
    KSelectionProxyModel *selectedBranchesRootsModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesRootsModel->setSourceModel(m_rootModel);
    selectedBranchesRootsModel->setFilterBehavior(KSelectionProxyModel::SubTreeRoots);

    QTreeView *selectedBranchesRootsView = createLabelledView(QStringLiteral("SubTreeRoots"), splitter);
    selectedBranchesRootsView->setModel(selectedBranchesRootsModel);
#endif

#ifdef SUBTREESWITHOUTROOTS
    KSelectionProxyModel *selectedBranchesChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesChildrenModel->setSourceModel(m_rootModel);
    selectedBranchesChildrenModel->setFilterBehavior(KSelectionProxyModel::SubTreesWithoutRoots);

    QTreeView *selectedBranchesChildrenView = createLabelledView(QStringLiteral("SubTreesWithoutRoots"), splitter);
    selectedBranchesChildrenView->setModel(selectedBranchesChildrenModel);
#endif

#ifdef EXACTSELECTION
    KSelectionProxyModel *onlySelectedModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    onlySelectedModel->setSourceModel(m_rootModel);
    onlySelectedModel->setFilterBehavior(KSelectionProxyModel::ExactSelection);

    QTreeView *onlySelectedView = createLabelledView(QStringLiteral("ExactSelection"), splitter);
    onlySelectedView->setModel(onlySelectedModel);
#endif

#ifdef CHILDRENOFEXACTSELECTION
    KSelectionProxyModel *onlySelectedChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    onlySelectedChildrenModel->setSourceModel(m_rootModel);
    onlySelectedChildrenModel->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection);

    QTreeView *onlySelectedChildrenView = createLabelledView(QStringLiteral("ChildrenOfExactSelection"), splitter);
    onlySelectedChildrenView->setModel(onlySelectedChildrenModel);
#endif
}
Example #17
0
QObject* FileSystemTab::component(Jerboa::Plugin::ComponentType type, QObject* parent)
{
	switch(type)
	{
		case Jerboa::Plugin::WidgetUsedWithPlaylist:
			{
				QFileSystemModel* model = new FileSystemModelWithToolTip(parent);
				model->setRootPath("/");
				model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs);
				model->setNameFilterDisables(false);

				QStringList musicGlobs;
				musicGlobs
					<< "*.aac"
					<< "*.aiff"
					<< "*.ape"
					<< "*.au"
					<< "*.cdda"
					<< "*.flac"
					<< "*.m4a"
					<< "*.mp3"
					<< "*.oga"
					<< "*.ogg"
					<< "*.ogm"
					<< "*.wav"
					<< "*.wma"
				;
				model->setNameFilters(musicGlobs);

				QTreeView* view = new QTreeView(qobject_cast<QWidget*>(parent));
				view->setWindowTitle("Files");
				view->setModel(model);
				view->setHeaderHidden(true);
				for(int i = 1; i < model->columnCount(); ++i)
				{
					view->setColumnHidden(i, true);
				}

				QString path = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);

				if(path.isEmpty() || !QDir(path).exists())
				{
					path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
				}

				const QModelIndex index(model->index(QSettings().value("collection/directory", path).toString()));
				for(QModelIndex iterator(index); iterator.isValid(); iterator = iterator.parent())
				{
					view->setExpanded(iterator, true);
				}

				view->setDragDropMode(QAbstractItemView::DragOnly);
				view->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
				view->setSelectionMode(QAbstractItemView::ExtendedSelection);

				connect(
					view,
					SIGNAL(doubleClicked(QModelIndex)),
					this,
					SLOT(addPathToPlaylist(QModelIndex))
				);

				QTimer* timer = new QTimer(this);
				connect(
					timer,
					SIGNAL(timeout()),
					this,
					SLOT(scrollToSelection())
				);
				timer->setSingleShot(true);
				timer->start(1000);

				m_view = view;
				return view;
			}
		default:
			return Jerboa::Plugin::component(type, parent);
	}
}