Bladeren bron

buggy tabs

master
hex 5 jaren geleden
bovenliggende
commit
08147e5c18
  1. 7
      include/window.h
  2. 9
      src/pane.cpp
  3. 1
      src/pane.h
  4. 29
      src/window.cpp

7
include/window.h

@ -6,14 +6,21 @@ @@ -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;
};

9
src/pane.cpp

@ -12,7 +12,10 @@ Pane::Pane(QWidget* parent) : @@ -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) { @@ -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
src/pane.h

@ -12,6 +12,7 @@ class Pane : public QWidget { @@ -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);

29
src/window.cpp

@ -11,6 +11,8 @@ @@ -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) : @@ -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)));
}

Laden…
Annuleren
Opslaan