Browse Source

fixed moc, top bar

master
hex 5 years ago
parent
commit
ca26e6e838
  1. 17
      CMakeLists.txt
  2. 4
      include/window.h
  3. 5
      src/pane.cpp
  4. 6
      src/pane.h
  5. 18
      src/window.cpp

17
CMakeLists.txt

@ -1,15 +1,22 @@ @@ -1,15 +1,22 @@
cmake_minimum_required (VERSION 3.6)
project ("hexfm")
file (GLOB_RECURSE SOURCES "src/*.cpp")
include_directories("./include")
find_package(Threads REQUIRED)
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC on)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_AUTOMOC on)
qt_wrap_cpp(hexfm SOURCES ./include/pane.h)
file (GLOB_RECURSE SOURCES "src/*.cpp")
include_directories("./include")
add_executable(hexfm ${SOURCES})
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
find_package(Qt5Widgets)
target_link_libraries(hexfm Qt5::Widgets ${CMAKE_THREAD_LIBS_INIT})

4
include/window.h

@ -5,8 +5,7 @@ @@ -5,8 +5,7 @@
class QPushButton;
class QListView;
class QFileSystemModel;
class QLineEdit;
class Window : public QWidget {
public:
@ -16,4 +15,5 @@ public slots: @@ -16,4 +15,5 @@ public slots:
private:
QPushButton *mButton;
QLineEdit *mPathBar;
};

5
src/pane.cpp

@ -25,11 +25,14 @@ Pane::Pane(QWidget* parent) : @@ -25,11 +25,14 @@ Pane::Pane(QWidget* parent) :
bool Pane::setPath(const QString& path) {
changeIndex(mModel->index(path));
return true;
}
void Pane::changeIndex(const QModelIndex& index) {
if (mModel->isDir(index)) {
mView->setRootIndex(index);
emit pathChanged(mModel->filePath(index));
} else {
//open file
}
@ -40,3 +43,5 @@ void Pane::moveUp() { @@ -40,3 +43,5 @@ void Pane::moveUp() {
}
}
#include "moc_pane.cpp"

6
include/pane.h → src/pane.h

@ -9,6 +9,7 @@ class QFileSystemModel; @@ -9,6 +9,7 @@ class QFileSystemModel;
namespace hex {
class Pane : public QWidget {
Q_OBJECT
public:
explicit Pane(QWidget *parent = 0);
@ -16,7 +17,10 @@ public slots: @@ -16,7 +17,10 @@ public slots:
bool setPath(const QString& path);
void changeIndex(const QModelIndex& index);
void moveUp();
signals:
void pathChanged(const QString& newPath);
private:
QListView* mView;
QFileSystemModel* mModel;

18
src/window.cpp

@ -10,19 +10,31 @@ @@ -10,19 +10,31 @@
#include <QVBoxLayout>
#include <QDesktopServices>
#include <QUrl>
#include <QLineEdit>
Window::Window(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout* navbar = new QVBoxLayout(this);
auto body = new QVBoxLayout(this);
auto navbar = new QHBoxLayout();
mButton = new QPushButton("^");
mPathBar = new QLineEdit();
navbar->addWidget(mButton);
navbar->addWidget(mPathBar);
body->addLayout(navbar);
auto pane = new hex::Pane;
navbar->addWidget(pane);
body->addWidget(pane);
this->setLayout(navbar);
this->setLayout(body);
QObject::connect(mButton, &QPushButton::clicked,
pane, &hex::Pane::moveUp);
QObject::connect(mPathBar, &QLineEdit::textChanged,
pane, &hex::Pane::setPath);
QObject::connect(pane, &hex::Pane::pathChanged,
mPathBar, &QLineEdit::setText);
}

Loading…
Cancel
Save