File indexing completed on 2024-04-21 14:56:11

0001 /*
0002     This file is part of the KDE libraries
0003     Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Library General Public
0007     License as published by the Free Software Foundation; either
0008     version 2 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Library General Public License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to
0017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018     Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "kfiletreeviewtest.h"
0022 
0023 #include <QApplication>
0024 #include <QDir>
0025 #include <QCheckBox>
0026 #include <QGridLayout>
0027 #include <QPushButton>
0028 
0029 #include <QUrl>
0030 
0031 #include <kfiletreeview_p.h>
0032 
0033 Window::Window()
0034     : KMainWindow(nullptr)
0035 {
0036     setObjectName("Test FileTreeView");
0037 
0038     QWidget *mainWidget = new QWidget(this);
0039     QGridLayout *layout = new QGridLayout(mainWidget);
0040 
0041     mTreeView = new KFileTreeView(mainWidget);
0042     layout->addWidget(mTreeView, 0, 1, 4, 1);
0043 
0044     QPushButton *button = new QPushButton("Root", mainWidget);
0045     layout->addWidget(button, 0, 0);
0046     connect(button, SIGNAL(clicked()), this, SLOT(showRoot()));
0047 
0048     button = new QPushButton("Home", mainWidget);
0049     layout->addWidget(button, 1, 0);
0050     connect(button, SIGNAL(clicked()), this, SLOT(showHome()));
0051 
0052     QCheckBox *dirOnlyMode = new QCheckBox("Show only Directories", mainWidget);
0053     layout->addWidget(dirOnlyMode, 2, 0);
0054     connect(dirOnlyMode, SIGNAL(toggled(bool)), mTreeView, SLOT(setDirOnlyMode(bool)));
0055 
0056     layout->setRowStretch(3, 1);
0057 
0058     setCentralWidget(mainWidget);
0059     resize(600, 400);
0060 }
0061 
0062 void Window::showHome()
0063 {
0064     mTreeView->setCurrentUrl(QUrl::fromLocalFile(QDir::home().absolutePath()));
0065 }
0066 
0067 void Window::showRoot()
0068 {
0069     mTreeView->setCurrentUrl(QUrl::fromLocalFile(QDir::root().absolutePath()));
0070 }
0071 
0072 int main(int argc, char **argv)
0073 {
0074     QApplication::setApplicationName("kfiletreeviewtest");
0075     QApplication app(argc, argv);
0076 
0077     Window *window = new Window;
0078     window->show();
0079 
0080     return app.exec();
0081 }
0082 
0083 #include "moc_kfiletreeviewtest.cpp"