Printing: add 1 dive per page option

With this option there is an exception, which makes the notes section of
the profile table occupy half the page. This way dive plans can reasonably
be printed.

Fixes #636

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2014-07-24 10:56:39 -07:00 committed by Dirk Hohndel
parent f29f41ae9e
commit 21585403db
6 changed files with 36 additions and 6 deletions

View file

@ -39,7 +39,8 @@ struct options {
enum { enum {
PRETTY, PRETTY,
TABLE, TABLE,
TWOPERPAGE TWOPERPAGE,
ONEPERPAGE
} type; } type;
int print_selected; int print_selected;
int color_selected; int color_selected;

View file

@ -68,6 +68,9 @@ void PrintLayout::print()
case options::PRETTY: case options::PRETTY:
printProfileDives(3, 2); printProfileDives(3, 2);
break; break;
case options::ONEPERPAGE:
printProfileDives(1, 1);
break;
case options::TWOPERPAGE: case options::TWOPERPAGE:
printProfileDives(2, 1); printProfileDives(2, 1);
break; break;
@ -167,7 +170,8 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
// create a model and table // create a model and table
ProfilePrintModel model; ProfilePrintModel model;
model.setFontsize(divesPerColumn == 1 ? 6.5 : 4.5); model.setFontsize(divesPerColumn == 1 ? 6.5 : 4.5);
QPointer<QTableView> table(createProfileTable(&model, scaledW)); // if there is only one dive per page row we pass fitNotesToHeight to be almost half the page height
QPointer<QTableView> table(createProfileTable(&model, scaledW, (divesPerRow == 1) ? scaledH * 0.45 : 0.0));
// profilePrintTableMaxH updates after the table is created // profilePrintTableMaxH updates after the table is created
const int tableH = profilePrintTableMaxH; const int tableH = profilePrintTableMaxH;
// resize the profile widget // resize the profile widget
@ -227,7 +231,7 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
} }
/* we create a table that has a fixed height, but can stretch to fit certain width */ /* we create a table that has a fixed height, but can stretch to fit certain width */
QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int tableW) QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int tableW, const qreal fitNotesToHeight)
{ {
// setup a new table // setup a new table
QTableView *table = new QTableView(); QTableView *table = new QTableView();
@ -266,14 +270,16 @@ QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int
table->setSpan(6, 0, 1, 5); table->setSpan(6, 0, 1, 5);
table->setSpan(7, 0, 5, 5); table->setSpan(7, 0, 5, 5);
/* resize row heights to the 'profilePrintRowHeights' indexes. /* resize row heights to the 'profilePrintRowHeights' indexes.
* profilePrintTableMaxH will then hold the table height. */ * profilePrintTableMaxH will then hold the table height.
* what fitNotesToHeight does it to expand the notes section to fit a special height */
int i; int i;
profilePrintTableMaxH = 0; profilePrintTableMaxH = 0;
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
int h = profilePrintRowHeights.at(i); int h = (i == rows - 1 && fitNotesToHeight != 0.0) ? fitNotesToHeight : profilePrintRowHeights.at(i);
profilePrintTableMaxH += h; profilePrintTableMaxH += h;
vHeader->resizeSection(i, h); vHeader->resizeSection(i, h);
} }
// resize columns. columns widths are percentages from the table width. // resize columns. columns widths are percentages from the table width.
int accW = 0; int accW = 0;
for (i = 0; i < cols; i++) { for (i = 0; i < cols; i++) {

View file

@ -38,7 +38,7 @@ private:
void setup(); void setup();
int estimateTotalDives() const; int estimateTotalDives() const;
void printProfileDives(int divesPerRow, int divesPerColumn); void printProfileDives(int divesPerRow, int divesPerColumn);
QTableView *createProfileTable(ProfilePrintModel *model, const int tableW); QTableView *createProfileTable(ProfilePrintModel *model, const int tableW, const qreal fitNotesToHeight = 0.0);
void printTable(); void printTable();
void addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const; void addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const;
void addTablePrintHeadingRow(TablePrintModel *model, int row) const; void addTablePrintHeadingRow(TablePrintModel *model, int row) const;

View file

@ -23,6 +23,9 @@ void PrintOptions::setup(struct options *printOpt)
case options::TWOPERPAGE: case options::TWOPERPAGE:
ui.radioTwoDives->setChecked(true); ui.radioTwoDives->setChecked(true);
break; break;
case options::ONEPERPAGE:
ui.radioOneDive->setChecked(true);
break;
case options::TABLE: case options::TABLE:
ui.radioTablePrint->setChecked(true); ui.radioTablePrint->setChecked(true);
break; break;
@ -44,6 +47,7 @@ void PrintOptions::setup(struct options *printOpt)
connect(ui.radioSixDives, SIGNAL(clicked(bool)), this, SLOT(radioSixDivesClicked(bool))); connect(ui.radioSixDives, SIGNAL(clicked(bool)), this, SLOT(radioSixDivesClicked(bool)));
connect(ui.radioTwoDives, SIGNAL(clicked(bool)), this, SLOT(radioTwoDivesClicked(bool))); connect(ui.radioTwoDives, SIGNAL(clicked(bool)), this, SLOT(radioTwoDivesClicked(bool)));
connect(ui.radioOneDive, SIGNAL(clicked(bool)), this, SLOT(radioOneDiveClicked(bool)));
connect(ui.radioTablePrint, SIGNAL(clicked(bool)), this, SLOT(radioTablePrintClicked(bool))); connect(ui.radioTablePrint, SIGNAL(clicked(bool)), this, SLOT(radioTablePrintClicked(bool)));
connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool))); connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool)));
@ -65,6 +69,11 @@ void PrintOptions::radioTwoDivesClicked(bool check)
printOptions->type = options::TWOPERPAGE; printOptions->type = options::TWOPERPAGE;
} }
void PrintOptions::radioOneDiveClicked(bool check)
{
printOptions->type = options::ONEPERPAGE;
}
void PrintOptions::radioTablePrintClicked(bool check) void PrintOptions::radioTablePrintClicked(bool check)
{ {
printOptions->type = options::TABLE; printOptions->type = options::TABLE;

View file

@ -22,6 +22,7 @@ private
slots: slots:
void radioSixDivesClicked(bool check); void radioSixDivesClicked(bool check);
void radioTwoDivesClicked(bool check); void radioTwoDivesClicked(bool check);
void radioOneDiveClicked(bool check);
void radioTablePrintClicked(bool check); void radioTablePrintClicked(bool check);
void printInColorClicked(bool check); void printInColorClicked(bool check);
void printSelectedClicked(bool check); void printSelectedClicked(bool check);

View file

@ -133,6 +133,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="radioOneDive">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>1 dive per page</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QRadioButton" name="radioTablePrint"> <widget class="QRadioButton" name="radioTablePrint">
<property name="sizePolicy"> <property name="sizePolicy">