File indexing completed on 2024-12-22 04:17:29

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2008 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 #include "defaultlabelpropertiestab.h"
0013 
0014 
0015 
0016 #include <math.h>
0017 
0018 namespace Kst {
0019 
0020 const double USLetterWidth = (11.0 - 1.0)*2.54; // 11 inches with a 1/2" margin in cm
0021 const double USLetterHeight = ((8.5 - 1)*2.54); // 8.5 inches, with a 1/2" margin, in cm.
0022 const double A4Width = (29.7 - 3.0); //  A4 with a 1.5 cm margin;
0023 const double A4Height = (21.0 - 3.0); // A4 with a 1.5 cm margin;
0024 const double J2cWidth = 9.0;
0025 const double J2cHeight = 9.0;
0026 
0027 DefaultLabelPropertiesTab::DefaultLabelPropertiesTab(QWidget *parent)
0028   : DialogTab(parent) {
0029 
0030   setupUi(this);
0031   setTabTitle(tr("Fonts"));
0032 
0033   _referenceViewSizeCombo->addItem(tr("Letter"/*, "US Letter sized paper"*/));
0034   _referenceViewSizeCombo->addItem(tr("A4"/*, "A4 sized paper"*/));
0035   _referenceViewSizeCombo->addItem(tr("Journal Plot"));
0036   _referenceViewSizeCombo->addItem(tr("Custom"/*, "Custom page size"*/));
0037 
0038   _referenceViewSizeCombo->setCurrentIndex(0);
0039   referenceViewSizeComboChanged(0);
0040 
0041   connect(_referenceViewSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(referenceViewSizeComboChanged(int)));
0042 
0043   connect(_refViewWidth, SIGNAL(valueChanged(double)), this, SIGNAL(modified()));
0044   connect(_refViewHeight, SIGNAL(valueChanged(double)), this, SIGNAL(modified()));
0045   connect(_minFontSize, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
0046 }
0047 
0048 
0049 DefaultLabelPropertiesTab::~DefaultLabelPropertiesTab() {
0050 }
0051 
0052 
0053 void DefaultLabelPropertiesTab::referenceViewSizeComboChanged(int i) {
0054   switch (i) {
0055   case 0: // US Letter
0056     _refViewWidth->setValue(USLetterWidth);
0057     _refViewWidth->setEnabled(false);
0058     _refViewHeight->setValue(USLetterHeight); // 8.5 inches, in cm, with a 1/2" margin.
0059     _refViewHeight->setEnabled(false);
0060     break;
0061   case 1: // A4 210 x 297 mm,
0062     _refViewWidth->setValue(A4Width); //  A4 with a 1.5 cm margin
0063     _refViewWidth->setEnabled(false);
0064     _refViewHeight->setValue(A4Height); // A4 with a 1.5 cm margin
0065     _refViewHeight->setEnabled(false);
0066     break;
0067   case 2: // half a page..
0068     _refViewWidth->setValue(J2cWidth);
0069     _refViewWidth->setEnabled(false);
0070     _refViewHeight->setValue(J2cHeight);
0071     _refViewHeight->setEnabled(false);
0072     break;
0073   case 3:
0074     _refViewWidth->setEnabled(true);
0075     _refViewHeight->setEnabled(true);
0076     break;
0077   default:
0078     _refViewWidth->setEnabled(true);
0079     _refViewHeight->setEnabled(true);
0080 
0081   }
0082 }
0083 
0084 double DefaultLabelPropertiesTab::referenceViewWidth() const {
0085   return (_refViewWidth->value());
0086 }
0087 
0088 
0089 void DefaultLabelPropertiesTab::setReferenceViewWidth(const double width) {
0090   _refViewWidth->setValue(width);
0091   checkSizeDefaults();
0092 }
0093 
0094 
0095 double DefaultLabelPropertiesTab::referenceViewHeight() const {
0096   return (_refViewHeight->value());
0097 }
0098 
0099 #define isClose(x,y) (fabs(x-y)<0.0001)
0100 void DefaultLabelPropertiesTab::checkSizeDefaults() {
0101   if (isClose(referenceViewHeight(),USLetterHeight) && isClose(referenceViewWidth(),USLetterWidth) &&
0102       (_referenceViewSizeCombo->currentIndex() !=0)) {
0103     _referenceViewSizeCombo->setCurrentIndex(0);
0104   } else if (isClose(referenceViewHeight(),A4Height) && isClose(referenceViewWidth(),A4Width) &&
0105       (_referenceViewSizeCombo->currentIndex() !=1)) {
0106     _referenceViewSizeCombo->setCurrentIndex(1);
0107   } else if (isClose(referenceViewHeight(),J2cHeight) && isClose(referenceViewWidth(),J2cWidth) &&
0108       (_referenceViewSizeCombo->currentIndex() !=2)) {
0109     _referenceViewSizeCombo->setCurrentIndex(2);
0110   } else {
0111     _referenceViewSizeCombo->setCurrentIndex(3); // custom
0112   }
0113 }
0114 
0115 void DefaultLabelPropertiesTab::setReferenceViewHeight(const double height) {
0116   _refViewHeight->setValue(height);
0117   checkSizeDefaults();
0118 }
0119 
0120 
0121 int DefaultLabelPropertiesTab::minimumFontSize() const {
0122   return _minFontSize->value();
0123 }
0124 
0125 
0126 void DefaultLabelPropertiesTab::setMinimumFontSize(const int points) {
0127   _minFontSize->setValue(points);
0128 }
0129 
0130 }
0131 
0132 // vim: ts=2 sw=2 et