Skip to content

Commit

Permalink
Add responsive to contributoriesWidget #237
Browse files Browse the repository at this point in the history
  • Loading branch information
KraTuX31 committed Apr 13, 2015
1 parent 02a59ef commit da6f4ad
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/gui/dialogs/addprojectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
namespace Gui {
namespace Dialogs {

AddProjectDialog::AddProjectDialog(int idProject, int noRowCustomer, QWidget *parent) :
QDialog(parent), ui(new Ui::AddProjectDialog)
AddProjectDialog::AddProjectDialog(
int idProject, int noRowCustomer, QWidget *parent)
: QDialog(parent), ui(new Ui::AddProjectDialog)
{
ui->setupUi(this);
Gui::Utils::WindowSettings::setPositionToCenter(*this);

ui->wdgSearch->selectCustomer(noRowCustomer);
ui->leNameProject->setFocus();
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/addprojectdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "models/customer.h"

#include "gui/mainwindow/mainwindow.h"
#include "gui/utils/windowsettings.h"

namespace Ui {
class AddProjectDialog;
Expand Down
10 changes: 8 additions & 2 deletions src/gui/dialogs/addquotedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ AddQuoteDialog::AddQuoteDialog(bool isBilling, int idCustomer, int id, bool copy
_idCustomer(idCustomer)
{
ui->setupUi(this);
ui->wdgContributories = new Gui::Widgets::ContributoriesWidget(QSharedPointer<Customer>(new Customer(idCustomer)), this);
connect(ui->wdgContributories, SIGNAL(contributoryChanged()), this, SLOT(updateBtn()));
Gui::Utils::WindowSettings::setPositionToCenter(*this);
ui->wdgContributories =
new Gui::Widgets::ContributoriesWidget(
QSharedPointer<Customer>(new Customer(idCustomer)), this);
connect(ui->wdgContributories,
SIGNAL(contributoryChanged()),
this,
SLOT(updateBtn()));

if (id != 0) {
_quote = new Billing(id);
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/addquotedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "database/billingdatabase.h"

#include "gui/widgets/contributorieswidget.h"
#include "gui/utils/windowsettings.h"

using namespace Models;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/startedwindowsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ StartedWindowsDialog::StartedWindowsDialog(QWidget *parent) :
ui(new Ui::StartedWindowsDialog)
{
ui->setupUi(this);

Gui::Utils::WindowSettings::setPositionToCenter(*this);
ui->wdgStack->setCurrentIndex(0);
ui->lbIcon->setPixmap(getImage(":/icons/FactDev"));
ui->wdgDbType->hide();
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/startedwindowsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QDialog>
#include "models/user.h"
#include "database/accessdatabase.h"
#include "gui/utils/windowsettings.h"
namespace Ui {
class StartedWindowsDialog;
}
Expand Down
11 changes: 6 additions & 5 deletions src/gui/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void MainWindow::setupUi()
ui->setupUi(this);

Utils::WindowSettings::setMaximumSize(*this);
Utils::WindowSettings::setPositionToCenter(*this);

_searchDock = new Docks::SearchDock();
addDockWidget(Qt::LeftDockWidgetArea, _searchDock);
Expand Down Expand Up @@ -148,7 +149,7 @@ void MainWindow::addDoc(bool isBilling) {

void MainWindow::resizeEvent(QResizeEvent *event)
{
switch (ui->stackedWidget->currentIndex()) {
switch (ui->stackedWidget->currentIndex()) {
case 0:
responsiveCustomerTable();
break;
Expand Down Expand Up @@ -244,12 +245,12 @@ void MainWindow::responsiveBillingTable()
ui->tblQuotes->setColumnWidth(6, 70);
} else {
ui->tblQuotes->hideColumn(0);
ui->tblQuotes->setColumnWidth(1, 40);
ui->tblQuotes->setColumnWidth(2, 60);
ui->tblQuotes->setColumnWidth(1, 30);
ui->tblQuotes->setColumnWidth(2, 70);
ui->tblQuotes->setColumnWidth(3, 200);
ui->tblQuotes->setColumnWidth(4, 250);
ui->tblQuotes->setColumnWidth(5, 130);
ui->tblQuotes->setColumnWidth(6, 50);
ui->tblQuotes->setColumnWidth(5, 100);
ui->tblQuotes->setColumnWidth(6, 70);
}
}

Expand Down
46 changes: 32 additions & 14 deletions src/gui/widgets/contributorieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ ContributoriesWidget::ContributoriesWidget(
ui->tblProjects->setItemDelegateForColumn(
2, new Delegates::DoubleSpinBoxDelegate());
ui->tblProjects->setModel(_modelProjects);
ui->btnAddPrestation->hide();
ui->btnRmovePrestation->hide();
ui->lbContributoriesProject->hide();
connect(ui->tblProjects->itemDelegateForColumn(0),
SIGNAL(closeEditor(QWidget*)),
SLOT(editing()));
emit contributoryChanged();
emit updateUi();
responsiveProjectsTable();
}

ContributoriesWidget::~ContributoriesWidget()
Expand Down Expand Up @@ -82,6 +80,27 @@ void ContributoriesWidget::add(ContributoriesList& list)
emit contributoryChanged();
}

void ContributoriesWidget::responsiveProjectsTable()
{

int w = ui->tblProjects->width();
double fixedRatio = 110;
ui->tblProjects->setColumnWidth(0,w*(0.99-(2*(fixedRatio/w))));
ui->tblProjects->setColumnWidth(1, fixedRatio);
ui->tblProjects->setColumnWidth(2, fixedRatio);
}

void ContributoriesWidget::responsiveContributoriesTable(QTableView* view)
{
int w = view->width();
double complete = 0.2 + 0.25 + 2*(100.0/w);
view->setColumnWidth(0, w*(0.2 + (0.99-complete)/2));
view->setColumnWidth(1, w*(0.25 + (1.0-complete)/2));
view->setColumnWidth(2, 100.0);
view->setColumnWidth(3, 100.0);
view->verticalHeader()->setDefaultSectionSize(60);
}

void ContributoriesWidget::remove(void)
{
QTableView* view = (QTableView*)ui->stack->currentWidget();
Expand All @@ -107,11 +126,6 @@ void ContributoriesWidget::addProject(QPair<Project*, Rate>* p)
view->setItemDelegateForColumn(1, new Delegates::TextareaDelegate());
view->setItemDelegateForColumn(2, new Delegates::DoubleSpinBoxDelegate());
view->setItemDelegateForColumn(3, new Delegates::UnitComboDelegate());
view->setColumnWidth(0, 200);
view->setColumnWidth(1, 450);
view->setColumnWidth(2, 70);
view->setColumnWidth(3, 70);
view->verticalHeader()->setDefaultSectionSize(60);

connect(view->itemDelegateForColumn(3),
SIGNAL(closeEditor(QWidget*)),
Expand All @@ -122,7 +136,11 @@ void ContributoriesWidget::addProject(QPair<Project*, Rate>* p)
connect(view->itemDelegateForColumn(1),
SIGNAL(closeEditor(QWidget*)),
SLOT(updatePrice()));



ui->stack->insertWidget(ui->stack->count(), view);
responsiveContributoriesTable(view);
emit updateUi();
}

Expand Down Expand Up @@ -164,15 +182,15 @@ void ContributoriesWidget::updateUi()
ui->tblProjects->currentIndex().row() != -1);

if(_modelProjects->getSelectedProjects().count() > 0) {
ui->btnAddPrestation->show();
ui->btnRmovePrestation->show();
ui->btnAddPrestation->setEnabled(true);
ui->btnRmovePrestation->setEnabled(true);
ui->lbContributoriesProject->show();
} else {
ui->btnAddPrestation->hide();
ui->btnRmovePrestation->hide();
ui->lbContributoriesProject->hide();
ui->btnAddPrestation->setEnabled(false);
ui->btnRmovePrestation->setEnabled(false);
ui->lbContributoriesProject->show();
}
updatePrice();
updatePrice();
}

void ContributoriesWidget::updatePrice()
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/contributorieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include <QStandardItem>
#include <QSpinBox>
#include <QTableView>

#include "models/contributory.h"
#include "models/contributorieslist.h"
Expand Down Expand Up @@ -59,6 +60,10 @@ class ContributoriesWidget : public QWidget
* @param list the <b>ContributoriesList</b>
*/
void add(ContributoriesList &list);

void responsiveProjectsTable();
void responsiveContributoriesTable(QTableView *view);

public slots:
/**
* @brief ContributoriesWidget::add Add a new empty contributory
Expand Down
33 changes: 28 additions & 5 deletions src/gui/widgets/contributorieswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>936</width>
<height>307</height>
<width>1028</width>
<height>415</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -50,9 +50,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>360</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>380</width>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -106,12 +112,25 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lbProjects">
<property name="text">
<string>Liste des projets</string>
<string>Liste des projets associés à la facture</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -221,7 +240,11 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QStackedWidget" name="stack"/>
<widget class="QStackedWidget" name="stack">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
Expand Down

0 comments on commit da6f4ad

Please sign in to comment.