Skip to content

Commit

Permalink
replace unit detail splitter with docks
Browse files Browse the repository at this point in the history
- removes the splitter and table/tree layout from the details dock, and
replaces them with a set of dockable widgets (ie. unit skills,
attributes, roles, etc. docks)
- by default the details pane is configured with docks tabified, however
they can be closed, floated, dragged and dropped to other configurations
  • Loading branch information
splintermind committed Nov 29, 2015
1 parent 6e18d0f commit 1cb3d98
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 71 deletions.
2 changes: 1 addition & 1 deletion inc/docks/dwarfdetailsdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DwarfDetailsDock : public BaseDock {
public slots:
void show_dwarf(Dwarf *d);
void clear(bool reinit = true);
QByteArray splitter_sizes();
QByteArray get_ui_state();

private:
DwarfDetailsWidget *m_widget;
Expand Down
3 changes: 2 additions & 1 deletion inc/dwarfdetailswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ THE SOFTWARE.

#include <QWidget>
#include <QTableWidget>
#include <QMainWindow>

class Dwarf;

Expand All @@ -45,7 +46,7 @@ public slots:
private:
Ui::DwarfDetailsWidget *ui;
QVector<QTableWidget*> m_tables;
QByteArray m_splitter_sizes;
QByteArray m_ui_state;

QList<QPair<int,Qt::SortOrder> > m_sorting;
int m_current_id;
Expand Down
11 changes: 6 additions & 5 deletions src/docks/dwarfdetailsdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <QSplitter>
#include <QMainWindow>
#include "basedock.h"
#include "dwarfdetailsdock.h"
#include "dwarfdetailswidget.h"
Expand Down Expand Up @@ -48,14 +49,14 @@ void DwarfDetailsDock::show_dwarf(Dwarf *d) {
m_initialized = true;
setWidget(m_widget);
m_widget->show();
}
}
m_current_id = d->id();
}

QByteArray DwarfDetailsDock::splitter_sizes(){
QSplitter* split = m_widget->findChild<QSplitter *>("details_splitter");
if(split)
return split->saveState();
QByteArray DwarfDetailsDock::get_ui_state(){
QMainWindow* dock_area = m_widget->findChild<QMainWindow *>("unit_details_dock_area");
if(dock_area)
return dock_area->saveState();
else
return NULL;
}
Expand Down
32 changes: 28 additions & 4 deletions src/dwarfdetailswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ DwarfDetailsWidget::DwarfDetailsWidget(QWidget *parent, Qt::WindowFlags flags)
{
ui->setupUi(this);

ui->splitter->setOpaqueResize(true);
ui->splitter->setObjectName("details_splitter"); //important!! this name is used to find the splitter and save it's state!!
//ui->splitter->setOpaqueResize(true);
//ui->splitter->setObjectName("details_splitter"); //important!! this name is used to find the splitter and save it's state!!

int default_size = 60;

Expand Down Expand Up @@ -133,8 +133,8 @@ DwarfDetailsWidget::DwarfDetailsWidget(QWidget *parent, Qt::WindowFlags flags)
ui->tw_health->setColumnCount(2);

//splitter
m_splitter_sizes = DT->user_settings()->value("gui_options/detailPanesSizes").toByteArray();
ui->splitter->restoreState(m_splitter_sizes);
m_ui_state = DT->user_settings()->value("gui_options/unit_detail_state").toByteArray();
//ui->splitter->restoreState(m_ui_state);

//skill sorts
m_sorting << qMakePair(1,Qt::DescendingOrder);
Expand All @@ -155,6 +155,30 @@ DwarfDetailsWidget::DwarfDetailsWidget(QWidget *parent, Qt::WindowFlags flags)
m_sorting << qMakePair(0,Qt::AscendingOrder);
ui->tw_health->sortItems(0, Qt::AscendingOrder);

QMainWindow *dock_area = new QMainWindow(this);
dock_area->setObjectName("unit_details_dock_area");
dock_area->setWindowFlags(Qt::Widget);
dock_area->setCentralWidget(0);
ui->verticalLayout->addWidget(dock_area);

foreach(QDockWidget *dw, this->findChildren<QDockWidget*>()){
dock_area->addDockWidget(Qt::TopDockWidgetArea,dw,Qt::Vertical);
}

if(m_ui_state.count() > 0){
dock_area ->restoreState(m_ui_state);
}else{
QDockWidget *first_dock = 0;
foreach(QDockWidget *dw, dock_area->findChildren<QDockWidget*>()){
if(first_dock == 0){
first_dock = dw;
}else{
dock_area->tabifyDockWidget(first_dock,dw);
}
}
ui->dock_unit_skills->raise();
}

}

DwarfDetailsWidget::~DwarfDetailsWidget() {
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ void MainWindow::write_settings() {

DwarfDetailsDock *dock = qobject_cast<DwarfDetailsDock*>(QObject::findChild<DwarfDetailsDock*>("dock_dwarf_details"));
if(dock){
QByteArray sizes = dock->splitter_sizes();
QByteArray sizes = dock->get_ui_state();
if(!sizes.isNull())
m_settings->setValue("detailPanesSizes", sizes);
m_settings->setValue("unit_detail_state", sizes);
}
m_settings->endGroup();

Expand Down
Loading

0 comments on commit 1cb3d98

Please sign in to comment.