mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Add a file list - items are overlapping but functionality is there.
This commit is contained in:
parent
a1563faac6
commit
2960f5abcb
8 changed files with 215 additions and 4 deletions
|
@ -12,15 +12,19 @@ set(CMAKE_AUTORCC ON)
|
|||
find_package(Qt5Core 5.1 REQUIRED)
|
||||
find_package(Qt5Qml 5.1 REQUIRED)
|
||||
find_package(Qt5Widgets 5.1 REQUIRED)
|
||||
find_package(Qt5Quick 5.1 REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
searcher.cpp
|
||||
$<$<AND:$<CONFIG:Release>,$<BOOL:${DINDEXER_ENABLE_QRC}>>:${CMAKE_CURRENT_BINARY_DIR}/reslist.qrc>
|
||||
icon_provider.cpp
|
||||
result_list_model.cpp
|
||||
)
|
||||
|
||||
set(qml_files
|
||||
qml/mainwin.qml
|
||||
qml/FileList.qml
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
|
@ -36,6 +40,7 @@ target_link_libraries(${PROJECT_NAME}
|
|||
PRIVATE Qt5::Qml
|
||||
PRIVATE Qt5::Widgets
|
||||
PRIVATE Qt5::Core
|
||||
PRIVATE Qt5::Quick
|
||||
PRIVATE glob2regex
|
||||
)
|
||||
|
||||
|
|
43
src/gui/icon_provider.cpp
Normal file
43
src/gui/icon_provider.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* Copyright 2015, 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "icon_provider.hpp"
|
||||
#include <QIcon>
|
||||
#include <QMimeType>
|
||||
#include <QMimeDatabase>
|
||||
|
||||
namespace din {
|
||||
IconProvider::IconProvider() :
|
||||
QQuickImageProvider(QQuickImageProvider::Pixmap)
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap IconProvider::requestPixmap (const QString& parID, QSize* parSize, const QSize& parRequestedSize) {
|
||||
const int width = (parRequestedSize.width() <= 0 ? 64 : parRequestedSize.width());
|
||||
const int height = (parRequestedSize.height() <= 0 ? 64 : parRequestedSize.height());
|
||||
|
||||
QMimeDatabase mime_db;
|
||||
QMimeType mime_type = mime_db.mimeTypeForName(parID);
|
||||
QIcon icon(QIcon::fromTheme(mime_type.iconName()));
|
||||
const QSize icon_size = icon.actualSize(QSize(width, height));
|
||||
|
||||
if (parSize)
|
||||
*parSize = icon_size;
|
||||
|
||||
return icon.pixmap(icon_size);
|
||||
}
|
||||
} //namespace din
|
32
src/gui/icon_provider.hpp
Normal file
32
src/gui/icon_provider.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright 2015, 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idFE04F9FAD3F64CABB69A9CC620FB731E
|
||||
#define idFE04F9FAD3F64CABB69A9CC620FB731E
|
||||
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
namespace din {
|
||||
class IconProvider : public QQuickImageProvider {
|
||||
public:
|
||||
IconProvider ( void );
|
||||
|
||||
QPixmap requestPixmap (const QString& parID, QSize* parSize, const QSize& parRequestedSize) override;
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
#endif
|
|
@ -19,9 +19,12 @@
|
|||
#include "dindexerConfig.h"
|
||||
#include "dindexer-guiConfig.h"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "icon_provider.hpp"
|
||||
#include "result_list_model.hpp"
|
||||
#include <QApplication>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -58,11 +61,15 @@
|
|||
int main (int parArgc, char* parArgv[]) {
|
||||
QApplication app(parArgc, parArgv);
|
||||
QQmlApplicationEngine engine;
|
||||
//const auto qml_path = replace_dindexer_path(
|
||||
// QML_PATH,
|
||||
// { {"APP_PATH", QCoreApplication::applicationDirPath().toStdString()} }
|
||||
//) + "mainwin.qml";
|
||||
din::ResultListModel result_list_model;
|
||||
|
||||
{
|
||||
QQmlContext* ctxt = engine.rootContext();
|
||||
assert(ctxt);
|
||||
ctxt->setContextProperty("resultListModel", &result_list_model);
|
||||
}
|
||||
|
||||
engine.addImageProvider(QLatin1String("theme"), new din::IconProvider);
|
||||
//engine.load(QUrl::fromLocalFile(QString::fromUtf8(qml_path.c_str(), qml_path.size())));
|
||||
engine.load(QUrl::fromLocalFile(QML_PATH "/mainwin.qml"));
|
||||
|
||||
|
|
38
src/gui/qml/FileList.qml
Normal file
38
src/gui/qml/FileList.qml
Normal file
|
@ -0,0 +1,38 @@
|
|||
import QtQuick 2.1
|
||||
|
||||
Item {
|
||||
Component {
|
||||
id: listDelegate
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
//height: imageSize.height
|
||||
|
||||
Image {
|
||||
id: itemIcon
|
||||
width: 64
|
||||
height: parent.height
|
||||
anchors.left: parent.left
|
||||
source: model.decoration
|
||||
}
|
||||
|
||||
Text {
|
||||
id: itemDesc
|
||||
anchors.left: itemIcon.right
|
||||
anchors.leftMargin: 20
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
font.pixelSize: 40
|
||||
text: model.display
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: fileListView
|
||||
anchors.fill: parent
|
||||
|
||||
model: resultListModel
|
||||
delegate: listDelegate
|
||||
spacing: 4
|
||||
orientation: ListView.Horizontal
|
||||
}
|
||||
}
|
|
@ -38,6 +38,9 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
FileList {
|
||||
}
|
||||
|
||||
statusBar: StatusBar {
|
||||
RowLayout {
|
||||
Label {
|
||||
|
|
48
src/gui/result_list_model.cpp
Normal file
48
src/gui/result_list_model.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* Copyright 2015, 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "result_list_model.hpp"
|
||||
#include <ciso646>
|
||||
|
||||
namespace din {
|
||||
ResultListModel::ResultListModel (QObject* parParent) :
|
||||
QAbstractListModel(parParent)
|
||||
{
|
||||
}
|
||||
|
||||
int ResultListModel::rowCount (const QModelIndex& parParent) const {
|
||||
if (parParent.isValid())
|
||||
return 0;
|
||||
return 3;
|
||||
}
|
||||
|
||||
QVariant ResultListModel::data (const QModelIndex& parIndex, int parRole) const {
|
||||
if (not parIndex.isValid())
|
||||
return QVariant();
|
||||
|
||||
switch (parRole) {
|
||||
case Qt::DisplayRole:
|
||||
return QString("Dummy text");
|
||||
|
||||
case Qt::DecorationRole:
|
||||
return QString("image://theme/audio/mp4");
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
} //namespace din
|
35
src/gui/result_list_model.hpp
Normal file
35
src/gui/result_list_model.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* Copyright 2015, 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idFBB6C468502C4ED2AF62A0EE46EB5DDE
|
||||
#define idFBB6C468502C4ED2AF62A0EE46EB5DDE
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractListModel>
|
||||
|
||||
namespace din {
|
||||
class ResultListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ResultListModel (QObject* parParent = nullptr);
|
||||
|
||||
virtual int rowCount (const QModelIndex& parParent=QModelIndex()) const override;
|
||||
virtual QVariant data (const QModelIndex& parIndex, int parRole=Qt::DisplayRole) const override;
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue