hex před 4 roky
rodič
revize
08147e5c18
4 změnil soubory, kde provedl 39 přidání a 7 odebrání
  1. 7
    0
      include/window.h
  2. 8
    1
      src/pane.cpp
  3. 1
    0
      src/pane.h
  4. 23
    6
      src/window.cpp

+ 7
- 0
include/window.h Zobrazit soubor

@@ -6,14 +6,21 @@

class QPushButton;
class QLineEdit;
class QTabWidget;
namespace hex {
class Pane;
}

class Window : public QWidget {
public:
explicit Window(QWidget *parent = 0);

public slots:
void switchActivePane(hex::Pane* newPane);
void switchActiveTab(int newTab);
private:
QPushButton *mButton;
QLineEdit *mPathBar;
QTabWidget *mTabWidget;
};

+ 8
- 1
src/pane.cpp Zobrazit soubor

@@ -12,7 +12,10 @@ Pane::Pane(QWidget* parent) :
auto layout = new QVBoxLayout;
mView = new QListView();
mModel = new QFileSystemModel();
mModel->setReadOnly(false);
mView->setModel(mModel);
mView->setSelectionMode(QAbstractItemView::ExtendedSelection);
mView->setDragDropMode(QAbstractItemView::DragDrop);
mModel->setRootPath("/");
setPath("/home/user");
layout->addWidget(mView);
@@ -39,7 +42,11 @@ void Pane::changeIndex(const QModelIndex& index) {
}

void Pane::moveUp() {
changeIndex(mView->rootIndex().parent());
changeIndex(mView->currentIndex().parent());
}

QString Pane::getPath() {
return mModel->filePath(mView->currentIndex());
}

}

+ 1
- 0
src/pane.h Zobrazit soubor

@@ -12,6 +12,7 @@ class Pane : public QWidget {
Q_OBJECT
public:
explicit Pane(QWidget *parent = 0);
QString getPath();

public slots:
bool setPath(const QString& path);

+ 23
- 6
src/window.cpp Zobrazit soubor

@@ -11,6 +11,8 @@
#include <QDesktopServices>
#include <QUrl>
#include <QLineEdit>
#include <QTabWidget>
#include <iostream>

Window::Window(QWidget *parent) :
QWidget(parent)
@@ -25,16 +27,31 @@ Window::Window(QWidget *parent) :
navbar->addWidget(mPathBar);

body->addLayout(navbar);
auto pane = new hex::Pane;
body->addWidget(pane);

mTabWidget = new QTabWidget;
body->addWidget(mTabWidget);
mTabWidget->addTab(new hex::Pane, "1");
mTabWidget->addTab(new hex::Pane, "2");
mTabWidget->addTab(new hex::Pane, "3");

QObject::connect(mTabWidget, &QTabWidget::currentChanged,
this, &Window::switchActiveTab);

this->setLayout(body);
}


void Window::switchActivePane(hex::Pane* newPane) {
mPathBar->setText(newPane->getPath());
QObject::connect(mButton, &QPushButton::clicked,
pane, &hex::Pane::moveUp);
QObject::connect(mPathBar, &QLineEdit::textChanged,
pane, &hex::Pane::setPath);
QObject::connect(pane, &hex::Pane::pathChanged,
newPane, &hex::Pane::moveUp);
//QObject::connect(mPathBar, &QLineEdit::textChanged,
// newPane, &hex::Pane::setPath);
QObject::connect(newPane, &hex::Pane::pathChanged,
mPathBar, &QLineEdit::setText);
}

void Window::switchActiveTab(int newTab) {
std::cout << newTab;
switchActivePane(dynamic_cast<hex::Pane*>(mTabWidget->widget(newTab)));
}

Načítá se…
Zrušit
Uložit