From 94275ffbf807d84bcc9bb57ebd22f589c3ca5f42 Mon Sep 17 00:00:00 2001 From: Dmintriy L. Kruglikov Date: Mon, 23 Jun 2008 18:30:25 +0300 Subject: [PATCH] Calendar and Calcilator muved into src/lib. Patched bugs in Calendar. Added Menu->Tools-> Calendar and Calculator --- src/ananas/aminicalc.cpp | 927 ---------------------------------------- src/ananas/aminicalc.h | 121 ------ src/ananas/ananas.pro | 9 +- src/ananas/ananasmainform.cpp | 13 + src/ananas/ananasmainform.h | 7 +- src/ananas/images/calendar.png | Bin 0 -> 1385 bytes src/lib/acalendar.cpp | 246 +++++++++++ src/lib/acalendar.h | 53 +++ src/lib/aminicalc.cpp | 927 ++++++++++++++++++++++++++++++++++++++++ src/lib/aminicalc.h | 121 ++++++ src/plugins/wfield.cpp | 244 +---------- 11 files changed, 1394 insertions(+), 1274 deletions(-) delete mode 100644 src/ananas/aminicalc.cpp delete mode 100644 src/ananas/aminicalc.h create mode 100644 src/ananas/images/calendar.png create mode 100644 src/lib/acalendar.cpp create mode 100644 src/lib/acalendar.h create mode 100644 src/lib/aminicalc.cpp create mode 100644 src/lib/aminicalc.h diff --git a/src/ananas/aminicalc.cpp b/src/ananas/aminicalc.cpp deleted file mode 100644 index 769f294..0000000 --- a/src/ananas/aminicalc.cpp +++ /dev/null @@ -1,927 +0,0 @@ -/**************************************************************************** -** Form implementation generated from reading ui file 'aminicalc.ui' -** -** Created: 2008-06-18T13:53:05 -** -** WARNING! All changes made in this file will be lost! -****************************************************************************/ - -#include "aminicalc.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Constructs a MiniCalc as a child of 'parent', with the - * name 'name' and widget flags set to 'f'. - * - * The dialog will by default be modeless, unless you set 'modal' to - * TRUE to construct a modal dialog. - */ -MiniCalc::MiniCalc( QWidget* parent, const char* name, bool modal, WFlags fl ) - : QDialog( parent, name, modal, fl ) -{ - if ( !name ) setName( "MiniCalc" ); - setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 1, 1, sizePolicy().hasHeightForWidth() ) ); - MiniCalcLayout = new QGridLayout( this, 1, 1, 1, 1, "MiniCalcLayout"); - MiniCalcLayout->setResizeMode( QLayout::Fixed ); - - sumInMemory = 0.0; - sumSoFar = 0.0; - factorSoFar = 0.0; - waitingForOperand = true; - - - calcFrame = new QFrame( this, "calcFrame" ); - calcFrame->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, calcFrame->sizePolicy().hasHeightForWidth() ) ); - calcFrame->setFrameShape( QFrame::StyledPanel ); - calcFrame->setFrameShadow( QFrame::Raised ); - calcFrameLayout = new QGridLayout( calcFrame, 1, 1, 1, 1, "calcFrameLayout"); - - extMem = new QPushButton( calcFrame, "extMem" ); - extMem->setMaximumSize( QSize( 25, 25 ) ); - extMem->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); - QFont extMem_font( extMem->font() ); - extMem_font.setPointSize( 8 ); - extMem->setFont( extMem_font ); - extMem->setToggleButton( TRUE ); - - calcFrameLayout->addWidget( extMem, 0, 0 ); - - display = new QLineEdit( calcFrame, "display" ); - QFont display_font( display->font() ); - display_font.setFamily( "xos4 Terminus" ); - display_font.setPointSize( 11 ); - display->setFont( display_font ); - display->setText("0"); - display->setReadOnly(true); - display->setAlignment(Qt::AlignRight); - display->setMaxLength(15); - display->installEventFilter(this); - - - calcFrameLayout->addMultiCellWidget( display, 0, 0, 1, 5 ); - - toDocButton = new QPushButton( calcFrame, "toDocButton" ); - toDocButton->setMaximumSize( QSize( 25, 25 ) ); - toDocButton->setPaletteBackgroundColor( QColor( 200, 200, 250 ) ); - QFont toDocButton_font( toDocButton->font() ); - toDocButton_font.setPointSize( 8 ); - toDocButton->setFont( toDocButton_font ); - - calcFrameLayout->addWidget( toDocButton, 0, 6 ); - - clearMemoryButton = new QPushButton( calcFrame, "clearMemoryButton" ); - clearMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearMemoryButton->sizePolicy().hasHeightForWidth() ) ); - clearMemoryButton->setMaximumSize( QSize( 25, 25 ) ); - clearMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); - QFont clearMemoryButton_font( clearMemoryButton->font() ); - clearMemoryButton_font.setPointSize( 8 ); - clearMemoryButton->setFont( clearMemoryButton_font ); - - calcFrameLayout->addWidget( clearMemoryButton, 1, 0 ); - - btn_7 = new QPushButton( calcFrame, "btn_7" ); - btn_7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_7->sizePolicy().hasHeightForWidth() ) ); - btn_7->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_7_font( btn_7->font() ); - btn_7_font.setPointSize( 8 ); - btn_7->setFont( btn_7_font ); - - calcFrameLayout->addWidget( btn_7, 1, 1 ); - - btn_8 = new QPushButton( calcFrame, "btn_8" ); - btn_8->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_8->sizePolicy().hasHeightForWidth() ) ); - btn_8->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_8_font( btn_8->font() ); - btn_8_font.setPointSize( 8 ); - btn_8->setFont( btn_8_font ); - - calcFrameLayout->addWidget( btn_8, 1, 2 ); - - btn_9 = new QPushButton( calcFrame, "btn_9" ); - btn_9->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_9->sizePolicy().hasHeightForWidth() ) ); - btn_9->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_9_font( btn_9->font() ); - btn_9_font.setPointSize( 8 ); - btn_9->setFont( btn_9_font ); - - calcFrameLayout->addWidget( btn_9, 1, 3 ); - - plusButton = new QPushButton( calcFrame, "plusButton" ); - plusButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, plusButton->sizePolicy().hasHeightForWidth() ) ); - plusButton->setMaximumSize( QSize( 25, 25 ) ); - plusButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont plusButton_font( plusButton->font() ); - plusButton_font.setPointSize( 8 ); - plusButton->setFont( plusButton_font ); - - calcFrameLayout->addWidget( plusButton, 1, 4 ); - - changeSignButton = new QPushButton( calcFrame, "changeSignButton" ); - changeSignButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, changeSignButton->sizePolicy().hasHeightForWidth() ) ); - changeSignButton->setMaximumSize( QSize( 25, 25 ) ); - changeSignButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont changeSignButton_font( changeSignButton->font() ); - changeSignButton_font.setPointSize( 8 ); - changeSignButton->setFont( changeSignButton_font ); - - calcFrameLayout->addWidget( changeSignButton, 1, 5 ); - - clearButton = new QPushButton( calcFrame, "clearButton" ); - clearButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearButton->sizePolicy().hasHeightForWidth() ) ); - clearButton->setMaximumSize( QSize( 25, 25 ) ); - clearButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); - QFont clearButton_font( clearButton->font() ); - clearButton_font.setPointSize( 8 ); - clearButton->setFont( clearButton_font ); - - calcFrameLayout->addWidget( clearButton, 1, 6 ); - - readMemoryButton = new QPushButton( calcFrame, "readMemoryButton" ); - readMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, readMemoryButton->sizePolicy().hasHeightForWidth() ) ); - readMemoryButton->setMaximumSize( QSize( 25, 25 ) ); - readMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); - QFont readMemoryButton_font( readMemoryButton->font() ); - readMemoryButton_font.setPointSize( 8 ); - readMemoryButton->setFont( readMemoryButton_font ); - - calcFrameLayout->addWidget( readMemoryButton, 2, 0 ); - - btn_4 = new QPushButton( calcFrame, "btn_4" ); - btn_4->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_4->sizePolicy().hasHeightForWidth() ) ); - btn_4->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_4_font( btn_4->font() ); - btn_4_font.setPointSize( 8 ); - btn_4->setFont( btn_4_font ); - - calcFrameLayout->addWidget( btn_4, 2, 1 ); - - btn_5 = new QPushButton( calcFrame, "btn_5" ); - btn_5->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_5->sizePolicy().hasHeightForWidth() ) ); - btn_5->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_5_font( btn_5->font() ); - btn_5_font.setPointSize( 8 ); - btn_5->setFont( btn_5_font ); - - calcFrameLayout->addWidget( btn_5, 2, 2 ); - - btn_6 = new QPushButton( calcFrame, "btn_6" ); - btn_6->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_6->sizePolicy().hasHeightForWidth() ) ); - btn_6->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_6_font( btn_6->font() ); - btn_6_font.setPointSize( 8 ); - btn_6->setFont( btn_6_font ); - - calcFrameLayout->addWidget( btn_6, 2, 3 ); - - minusButton = new QPushButton( calcFrame, "minusButton" ); - minusButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, minusButton->sizePolicy().hasHeightForWidth() ) ); - minusButton->setMaximumSize( QSize( 25, 25 ) ); - minusButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont minusButton_font( minusButton->font() ); - minusButton_font.setPointSize( 8 ); - minusButton->setFont( minusButton_font ); - - calcFrameLayout->addWidget( minusButton, 2, 4 ); - - persentButton = new QPushButton( calcFrame, "persentButton" ); - persentButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, persentButton->sizePolicy().hasHeightForWidth() ) ); - persentButton->setMaximumSize( QSize( 25, 25 ) ); - persentButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont persentButton_font( persentButton->font() ); - persentButton_font.setPointSize( 8 ); - persentButton->setFont( persentButton_font ); - - calcFrameLayout->addWidget( persentButton, 2, 5 ); - - clearAllButton = new QPushButton( calcFrame, "clearAllButton" ); - clearAllButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearAllButton->sizePolicy().hasHeightForWidth() ) ); - clearAllButton->setMaximumSize( QSize( 25, 25 ) ); - clearAllButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); - QFont clearAllButton_font( clearAllButton->font() ); - clearAllButton_font.setPointSize( 8 ); - clearAllButton->setFont( clearAllButton_font ); - - calcFrameLayout->addWidget( clearAllButton, 2, 6 ); - - minusMemoryButton = new QPushButton( calcFrame, "minusMemoryButton" ); - minusMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, minusMemoryButton->sizePolicy().hasHeightForWidth() ) ); - minusMemoryButton->setMaximumSize( QSize( 25, 25 ) ); - minusMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); - QFont minusMemoryButton_font( minusMemoryButton->font() ); - minusMemoryButton_font.setPointSize( 8 ); - minusMemoryButton->setFont( minusMemoryButton_font ); - - calcFrameLayout->addWidget( minusMemoryButton, 3, 0 ); - - btn_1 = new QPushButton( calcFrame, "btn_1" ); - btn_1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_1->sizePolicy().hasHeightForWidth() ) ); - btn_1->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_1_font( btn_1->font() ); - btn_1_font.setPointSize( 8 ); - btn_1->setFont( btn_1_font ); - - calcFrameLayout->addWidget( btn_1, 3, 1 ); - - btn_2 = new QPushButton( calcFrame, "btn_2" ); - btn_2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_2->sizePolicy().hasHeightForWidth() ) ); - btn_2->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_2_font( btn_2->font() ); - btn_2_font.setPointSize( 8 ); - btn_2->setFont( btn_2_font ); - - calcFrameLayout->addWidget( btn_2, 3, 2 ); - - btn_3 = new QPushButton( calcFrame, "btn_3" ); - btn_3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_3->sizePolicy().hasHeightForWidth() ) ); - btn_3->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_3_font( btn_3->font() ); - btn_3_font.setPointSize( 8 ); - btn_3->setFont( btn_3_font ); - - calcFrameLayout->addWidget( btn_3, 3, 3 ); - - timesButton = new QPushButton( calcFrame, "timesButton" ); - timesButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, timesButton->sizePolicy().hasHeightForWidth() ) ); - timesButton->setMaximumSize( QSize( 25, 25 ) ); - timesButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont timesButton_font( timesButton->font() ); - timesButton_font.setPointSize( 8 ); - timesButton->setFont( timesButton_font ); - - calcFrameLayout->addWidget( timesButton, 3, 4 ); - - reciprocalButton = new QPushButton( calcFrame, "reciprocalButton" ); - reciprocalButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, reciprocalButton->sizePolicy().hasHeightForWidth() ) ); - reciprocalButton->setMaximumSize( QSize( 25, 25 ) ); - reciprocalButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont reciprocalButton_font( reciprocalButton->font() ); - reciprocalButton_font.setPointSize( 8 ); - reciprocalButton->setFont( reciprocalButton_font ); - - calcFrameLayout->addWidget( reciprocalButton, 3, 5 ); - - backspaceButton = new QPushButton( calcFrame, "backspaceButton" ); - backspaceButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, backspaceButton->sizePolicy().hasHeightForWidth() ) ); - backspaceButton->setMaximumSize( QSize( 25, 25 ) ); - backspaceButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); - QFont backspaceButton_font( backspaceButton->font() ); - backspaceButton_font.setPointSize( 8 ); - backspaceButton->setFont( backspaceButton_font ); - - calcFrameLayout->addWidget( backspaceButton, 3, 6 ); - - addToMemoryButton = new QPushButton( calcFrame, "addToMemoryButton" ); - addToMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, addToMemoryButton->sizePolicy().hasHeightForWidth() ) ); - addToMemoryButton->setMaximumSize( QSize( 25, 25 ) ); - addToMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); - QFont addToMemoryButton_font( addToMemoryButton->font() ); - addToMemoryButton_font.setPointSize( 8 ); - addToMemoryButton->setFont( addToMemoryButton_font ); - - calcFrameLayout->addWidget( addToMemoryButton, 4, 0 ); - - btn_0 = new QPushButton( calcFrame, "btn_0" ); - btn_0->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_0->sizePolicy().hasHeightForWidth() ) ); - btn_0->setMaximumSize( QSize( 25, 25 ) ); - QFont btn_0_font( btn_0->font() ); - btn_0_font.setPointSize( 8 ); - btn_0->setFont( btn_0_font ); - - calcFrameLayout->addWidget( btn_0, 4, 1 ); - - doubleZero = new QPushButton( calcFrame, "doubleZero" ); - doubleZero->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, doubleZero->sizePolicy().hasHeightForWidth() ) ); - doubleZero->setMaximumSize( QSize( 25, 25 ) ); - QFont doubleZero_font( doubleZero->font() ); - doubleZero_font.setPointSize( 8 ); - doubleZero->setFont( doubleZero_font ); - - calcFrameLayout->addWidget( doubleZero, 4, 2 ); - - pointButton = new QPushButton( calcFrame, "pointButton" ); - pointButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, pointButton->sizePolicy().hasHeightForWidth() ) ); - pointButton->setMaximumSize( QSize( 25, 25 ) ); - QFont pointButton_font( pointButton->font() ); - pointButton_font.setPointSize( 8 ); - pointButton->setFont( pointButton_font ); - - calcFrameLayout->addWidget( pointButton, 4, 3 ); - - divisionButton = new QPushButton( calcFrame, "divisionButton" ); - divisionButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, divisionButton->sizePolicy().hasHeightForWidth() ) ); - divisionButton->setMaximumSize( QSize( 25, 25 ) ); - divisionButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont divisionButton_font( divisionButton->font() ); - divisionButton_font.setPointSize( 8 ); - divisionButton->setFont( divisionButton_font ); - - calcFrameLayout->addWidget( divisionButton, 4, 4 ); - - powButton = new QPushButton( calcFrame, "powButton" ); - powButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, powButton->sizePolicy().hasHeightForWidth() ) ); - powButton->setMaximumSize( QSize( 25, 25 ) ); - powButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); - QFont powButton_font( powButton->font() ); - powButton_font.setPointSize( 8 ); - powButton->setFont( powButton_font ); - - calcFrameLayout->addWidget( powButton, 4, 5 ); - - equalButton = new QPushButton( calcFrame, "equalButton" ); - equalButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, equalButton->sizePolicy().hasHeightForWidth() ) ); - equalButton->setMaximumSize( QSize( 25, 25 ) ); - equalButton->setPaletteBackgroundColor( QColor( 200, 200, 250 ) ); - QFont equalButton_font( equalButton->font() ); - equalButton_font.setPointSize( 8 ); - equalButton->setFont( equalButton_font ); - - calcFrameLayout->addWidget( equalButton, 4, 6 ); - - MiniCalcLayout->addWidget( calcFrame, 0, 0 ); - - extension = new QFrame( this, "extension" ); - extension->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, extension->sizePolicy().hasHeightForWidth() ) ); - extension->setFrameShape( QFrame::StyledPanel ); - extension->setFrameShadow( QFrame::Raised ); - extensionLayout = new QGridLayout( extension, 1, 1, 1, 1, "extensionLayout"); - - label = new QLabel( extension, "label" ); - label->setMinimumSize( QSize( 0, 20 ) ); - QFont label_font( label->font() ); - label_font.setPointSize( 8 ); - label->setFont( label_font ); - //label->setAlignment( int( QLabel::AlignCenter ) ); - - extensionLayout->addMultiCellWidget( label, 0, 0, 0, 2 ); - - mem_1 = new QLineEdit( extension, "mem_1" ); - QFont mem_1_font( mem_1->font() ); - mem_1_font.setPointSize( 10 ); - mem_1->setFont( mem_1_font ); - - extensionLayout->addWidget( mem_1, 1, 2 ); - - mem_to_disp_4 = new QPushButton( extension, "mtd_4" ); - mem_to_disp_4->setMaximumSize( QSize( 25, 25 ) ); - QFont mem_to_disp_4_font( mem_to_disp_4->font() ); - mem_to_disp_4_font.setPointSize( 8 ); - mem_to_disp_4->setFont( mem_to_disp_4_font ); - - extensionLayout->addWidget( mem_to_disp_4, 4, 1 ); - - disp_to_mem_4 = new QPushButton( extension, "dtm_4" ); - disp_to_mem_4->setMaximumSize( QSize( 25, 25 ) ); - QFont disp_to_mem_4_font( disp_to_mem_4->font() ); - disp_to_mem_4_font.setPointSize( 8 ); - disp_to_mem_4->setFont( disp_to_mem_4_font ); - - extensionLayout->addWidget( disp_to_mem_4, 4, 0 ); - - mem_to_disp_3 = new QPushButton( extension, "mtd_3" ); - mem_to_disp_3->setMaximumSize( QSize( 25, 25 ) ); - QFont mem_to_disp_3_font( mem_to_disp_3->font() ); - mem_to_disp_3_font.setPointSize( 8 ); - mem_to_disp_3->setFont( mem_to_disp_3_font ); - - extensionLayout->addWidget( mem_to_disp_3, 3, 1 ); - - disp_to_mem_3 = new QPushButton( extension, "dtm_3" ); - disp_to_mem_3->setMaximumSize( QSize( 25, 25 ) ); - QFont disp_to_mem_3_font( disp_to_mem_3->font() ); - disp_to_mem_3_font.setPointSize( 8 ); - disp_to_mem_3->setFont( disp_to_mem_3_font ); - - extensionLayout->addWidget( disp_to_mem_3, 3, 0 ); - - disp_to_mem_1 = new QPushButton( extension, "dtm_1" ); - disp_to_mem_1->setMaximumSize( QSize( 25, 25 ) ); - QFont disp_to_mem_1_font( disp_to_mem_1->font() ); - disp_to_mem_1_font.setPointSize( 8 ); - disp_to_mem_1->setFont( disp_to_mem_1_font ); - - extensionLayout->addWidget( disp_to_mem_1, 1, 0 ); - - mem_4 = new QLineEdit( extension, "mem_4" ); - QFont mem_4_font( mem_4->font() ); - mem_4_font.setPointSize( 10 ); - mem_4->setFont( mem_4_font ); - - extensionLayout->addWidget( mem_4, 4, 2 ); - - mem_3 = new QLineEdit( extension, "mem_3" ); - QFont mem_3_font( mem_3->font() ); - mem_3_font.setPointSize( 10 ); - mem_3->setFont( mem_3_font ); - - extensionLayout->addWidget( mem_3, 3, 2 ); - - disp_to_mem_2 = new QPushButton( extension, "dtm_2" ); - disp_to_mem_2->setMaximumSize( QSize( 25, 25 ) ); - QFont disp_to_mem_2_font( disp_to_mem_2->font() ); - disp_to_mem_2_font.setPointSize( 8 ); - disp_to_mem_2->setFont( disp_to_mem_2_font ); - - extensionLayout->addWidget( disp_to_mem_2, 2, 0 ); - - mem_2 = new QLineEdit( extension, "mem_2" ); - QFont mem_2_font( mem_2->font() ); - mem_2_font.setPointSize( 10 ); - mem_2->setFont( mem_2_font ); - - extensionLayout->addWidget( mem_2, 2, 2 ); - - mem_to_disp_2 = new QPushButton( extension, "mtd_2" ); - mem_to_disp_2->setMaximumSize( QSize( 25, 25 ) ); - QFont mem_to_disp_2_font( mem_to_disp_2->font() ); - mem_to_disp_2_font.setPointSize( 8 ); - mem_to_disp_2->setFont( mem_to_disp_2_font ); - - extensionLayout->addWidget( mem_to_disp_2, 2, 1 ); - - mem_to_disp_1 = new QPushButton( extension, "mtd_1" ); - mem_to_disp_1->setMaximumSize( QSize( 25, 25 ) ); - QFont mem_to_disp_1_font( mem_to_disp_1->font() ); - mem_to_disp_1_font.setPointSize( 8 ); - mem_to_disp_1->setFont( mem_to_disp_1_font ); - - extensionLayout->addWidget( mem_to_disp_1, 1, 1 ); - - MiniCalcLayout->addWidget( extension, 1, 0 ); - languageChange(); - resize( QSize(210, 233).expandedTo(minimumSizeHint()) ); - clearWState( WState_Polished ); - - extension->hide(); - clearMemoryButton->setDisabled(true); - readMemoryButton->setDisabled(true); - - // signals and slots connections - connect( extMem, SIGNAL( clicked() ), this, SLOT( extMemClicked() ) ); - connect( btn_0, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_1, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_2, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_3, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_4, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_5, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_6, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_7, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_8, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( btn_9, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); - connect( mem_to_disp_1, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( mem_to_disp_2, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( mem_to_disp_3, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( mem_to_disp_4, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( disp_to_mem_1, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( disp_to_mem_2, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( disp_to_mem_3, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( disp_to_mem_4, SIGNAL( clicked() ), this, SLOT(extMemOperations())); - connect( backspaceButton, SIGNAL( clicked() ), this, SLOT(backspaceClicked())); - connect( changeSignButton, SIGNAL( clicked() ), this, SLOT(changeSignClicked())); - connect( reciprocalButton, SIGNAL( clicked() ), this, SLOT( unaryOperatorClicked() ) ); - connect( powButton, SIGNAL( clicked() ), this, SLOT( unaryOperatorClicked() ) ); - connect( divisionButton, SIGNAL( clicked() ), this, SLOT( multiplicativeOperatorClicked() ) ); - connect( timesButton, SIGNAL( clicked() ), this, SLOT( multiplicativeOperatorClicked() ) ); - connect( minusButton, SIGNAL( clicked() ), this, SLOT( additiveOperatorClicked() ) ); - connect( plusButton, SIGNAL( clicked() ), this, SLOT( additiveOperatorClicked() ) ); - connect( persentButton, SIGNAL( clicked() ), this, SLOT( percentClicked() ) ); - connect( equalButton, SIGNAL( clicked() ), this, SLOT( equalClicked() ) ); - connect( doubleZero, SIGNAL( clicked() ), this, SLOT( dzClicked() ) ); - connect( pointButton, SIGNAL( clicked() ), this, SLOT( pointClicked() ) ); - connect( clearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); - connect( clearAllButton, SIGNAL( clicked() ), this, SLOT( clearAll() ) ); - connect( clearMemoryButton, SIGNAL( clicked() ), this, SLOT( clearMemory() ) ); - connect( toDocButton, SIGNAL( clicked() ), this, SLOT( toDoc() ) ); - connect( clearMemoryButton, SIGNAL( clicked() ), this, SLOT( clearMemory() ) ); - connect( readMemoryButton, SIGNAL( clicked() ), this, SLOT( readMemory() ) ); - connect( minusMemoryButton, SIGNAL( clicked() ), this, SLOT( minusMemory() ) ); - connect( addToMemoryButton, SIGNAL( clicked() ), this, SLOT( addToMemory() ) ); - -} - -/* - * Destroys the object and frees any allocated resources - */ -MiniCalc::~MiniCalc() -{ - // no need to delete child widgets, Qt does it all for us -} - -/* - * Sets the strings of the subwidgets using the current - * language. - */ -void MiniCalc::languageChange() -{ - setCaption( tr( "A-Calc" ) ); - extMem->setText( tr( "ME" ) ); - toDocButton->setText( tr( "->" ) ); - clearMemoryButton->setText( tr( "MC" ) ); - btn_7->setText( tr( "7" ) ); - btn_8->setText( tr( "8" ) ); - btn_9->setText( tr( "9" ) ); - plusButton->setText( tr( "+" ) ); - changeSignButton->setText( tr( "\261" ) ); - clearButton->setText( tr( "C" ) ); - readMemoryButton->setText( tr( "MR" ) ); - btn_4->setText( tr( "4" ) ); - btn_5->setText( tr( "5" ) ); - btn_6->setText( tr( "6" ) ); - minusButton->setText( tr( "-" ) ); - persentButton->setText( tr( "%" ) ); - clearAllButton->setText( tr( "CE" ) ); - minusMemoryButton->setText( tr( "M-" ) ); - btn_1->setText( tr( "1" ) ); - btn_2->setText( tr( "2" ) ); - btn_3->setText( tr( "3" ) ); - timesButton->setText( tr( "\327" ) ); - reciprocalButton->setText( tr( "1/X" ) ); - backspaceButton->setText( tr( "<-" ) ); - addToMemoryButton->setText( tr( "M+" ) ); - btn_0->setText( tr( "0" ) ); - doubleZero->setText( tr( "00" ) ); - pointButton->setText( tr( "." ) ); - divisionButton->setText( tr( "/" ) ); - powButton->setText( tr( "x\262" ) ); - equalButton->setText( tr( "=" ) ); - label->setText( tr( "In memory: 0" ) ); - mem_to_disp_4->setText( tr( "<" ) ); - disp_to_mem_4->setText( tr( ">" ) ); - mem_to_disp_3->setText( tr( "<" ) ); - disp_to_mem_3->setText( tr( ">" ) ); - disp_to_mem_1->setText( tr( ">" ) ); - disp_to_mem_2->setText( tr( ">" ) ); - mem_to_disp_2->setText( tr( "<" ) ); - mem_to_disp_1->setText( tr( "<" ) ); -} - - -/* - * Open a extended memory cells - */ -void MiniCalc::extMemClicked() -{ - if ( !extension->isVisibleTo(0) ) { - extension->show(); - setCaption( tr( "A-Calc +" ) ); - } else { - extension->hide(); - setCaption( tr( "A-Calc" ) ); - } - return; -} - - -void MiniCalc::digitClicked() -{ - QPushButton *clickedButton = (QPushButton*)sender(); - int digitValue = clickedButton->text().toInt(); - if (display->text() == "0" && digitValue == 0.0) - return; - - if (waitingForOperand) { - display->clear(); - waitingForOperand = false; - } - display->setText(display->text() + QString::number(digitValue)); - -} - - -void MiniCalc::dzClicked() -{ - double operand = display->text().toDouble(); - double result = 0.0; - if (operand > 0.0) { - result = operand * 100; - display->setText(QString::number(result)); - } - else {return;} -} - -void MiniCalc::unaryOperatorClicked() -{ - QPushButton *clickedButton = (QPushButton*)sender(); - QString clickedOperator = clickedButton->text(); - double operand = display->text().toDouble(); - double result = 0.0; - - - if (clickedOperator == tr("x\262")) { - result = pow(operand, 2.0); - } else if (clickedOperator == tr("1/X")) { - if (operand == 0.0) { - abortOperation(); - return; - } - result = 1.0 / operand; - } - display->setText(QString::number(result)); - waitingForOperand = true; -} - - -void MiniCalc::additiveOperatorClicked() -{ - QPushButton *clickedButton = (QPushButton*)sender(); - QString clickedOperator = clickedButton->text(); - double operand = display->text().toDouble(); - - if (!pendingMultiplicativeOperator.isEmpty()) { - if (!calculate(operand, pendingMultiplicativeOperator)) { - abortOperation(); - return; - } - display->setText(QString::number(factorSoFar)); - operand = factorSoFar; - factorSoFar = 0.0; - pendingMultiplicativeOperator.truncate(0); - } - - if (!pendingAdditiveOperator.isEmpty()) { - if (!calculate(operand, pendingAdditiveOperator)) { - abortOperation(); - return; - } - display->setText(QString::number(sumSoFar)); - } else { - sumSoFar = operand; - } - - pendingAdditiveOperator = clickedOperator; - waitingForOperand = true; -} - - -void MiniCalc::multiplicativeOperatorClicked() -{ - QPushButton *clickedButton = (QPushButton*)sender(); - QString clickedOperator = clickedButton->text(); - double operand = display->text().toDouble(); - - if (!pendingMultiplicativeOperator.isEmpty()) { - if (!calculate(operand, pendingMultiplicativeOperator)) { - abortOperation(); - return; - } - display->setText(QString::number(factorSoFar)); - } else { - factorSoFar = operand; - } - - pendingMultiplicativeOperator = clickedOperator; - waitingForOperand = true; -} - - -void MiniCalc::pointClicked() -{ - if (waitingForOperand) - display->setText("0"); - if (!display->text().contains(".")) - display->setText(display->text() + tr(".")); - waitingForOperand = false; -} - - -void MiniCalc::changeSignClicked() -{ - QString text = display->text(); - double value = text.toDouble(); - - if (value > 0.0) { - text.prepend(tr("-")); - } else if (value < 0.0) { - text.remove(0, 1); - } - display->setText(text); -} - - -void MiniCalc::backspaceClicked() -{ - if (waitingForOperand) return; - - QString text = display->text(); - display->end(false); - display->backspace(); - if (text.isEmpty()) { - text = "0"; - waitingForOperand = true; - display->setText(text); - } - -} - - -void MiniCalc::clear() -{ - if (waitingForOperand) return; - display->setText("0"); - waitingForOperand = true; -} - - -void MiniCalc::clearAll() -{ - sumSoFar = 0.0; - factorSoFar = 0.0; - pendingAdditiveOperator.truncate(0); - pendingMultiplicativeOperator.truncate(0); - display->setText("0"); - waitingForOperand = true; -} - - -void MiniCalc::clearMemory() -{ - sumInMemory = 0.0; - clearMemoryButton->setDisabled(true); - readMemoryButton->setDisabled(true); - label->setText(QString("In memory: %1").arg(sumInMemory)); -} - -/* -* Return calculated value to Document -*/ -void MiniCalc::toDoc() -{ -// Sorry, later... -} - - -void MiniCalc::readMemory() -{ - display->setText(QString::number(sumInMemory)); - waitingForOperand = true; -} - - -void MiniCalc::minusMemory() -{ - equalClicked(); - sumInMemory -= display->text().toDouble(); - clearMemoryButton->setEnabled(true); - readMemoryButton->setEnabled(true); - label->setText(QString("In memory: %1").arg(sumInMemory)); -} - - -void MiniCalc::addToMemory() -{ - equalClicked(); - sumInMemory += display->text().toDouble(); - clearMemoryButton->setEnabled(true); - readMemoryButton->setEnabled(true); - label->setText(QString("In memory: %1").arg(sumInMemory)); -} - - -void MiniCalc::abortOperation() -{ - clearAll(); - display->setText(tr("ERROR")); -} - - -bool MiniCalc::calculate(double rightOperand, const QString &pendingOperator) -{ - if (pendingOperator == tr("+")) { - sumSoFar += rightOperand; - } else if (pendingOperator == tr("-")) { - sumSoFar -= rightOperand; - } else if (pendingOperator == tr("\327")) { - factorSoFar *= rightOperand; - } else if (pendingOperator == tr("/")) { - if (rightOperand == 0.0) - return false; - factorSoFar /= rightOperand; - } - return true; -} - - -void MiniCalc::extMemOperations() -{ - QPushButton *clickedButton = (QPushButton*)sender(); - QString clickedOperator = clickedButton->name(); - - if (clickedOperator == "dtm_1") { - QString text = display->text(); - mem_1->setText(text); - } else if (clickedOperator == "dtm_2"){ - QString text = display->text(); - mem_2->setText(text); - } else if (clickedOperator == "dtm_3"){ - QString text = display->text(); - mem_3->setText(text); - } else if (clickedOperator == "dtm_4"){ - QString text = display->text(); - mem_4->setText(text); - } else if (clickedOperator == "mtd_1"){ - QString text = mem_1->text(); - display->setText(text); - } else if (clickedOperator == "mtd_2"){ - QString text = mem_2->text(); - display->setText(text); - } else if (clickedOperator == "mtd_3"){ - QString text = mem_3->text(); - display->setText(text); - } else if (clickedOperator == "mtd_4"){ - QString text = mem_4->text(); - display->setText(text); - } - -} - - -void MiniCalc::equalClicked() -{ - double operand = display->text().toDouble(); - - if (!pendingMultiplicativeOperator.isEmpty()) { - if (!calculate(operand, pendingMultiplicativeOperator)) { - abortOperation(); - return; - } - operand = factorSoFar; - factorSoFar = 0.0; - pendingMultiplicativeOperator.truncate( 0 ); - } - if (!pendingAdditiveOperator.isEmpty()) { - if (!calculate(operand, pendingAdditiveOperator)) { - abortOperation(); - return; - } - pendingAdditiveOperator.truncate(0); - } else { - sumSoFar = operand; - } - - display->setText(QString::number(sumSoFar)); - sumSoFar = 0.0; - waitingForOperand = true; -} - - -bool MiniCalc::calcpercent(double rightOperand, const QString &pendingOperator) -{ - if (pendingOperator == tr("+")) { - sumSoFar = sumSoFar + ((sumSoFar / 100) * rightOperand); - - } else if (pendingOperator == tr("-")) { - sumSoFar = sumSoFar - ((sumSoFar / 100) * rightOperand); - - } else if (pendingOperator == tr("\327")) { - factorSoFar = (factorSoFar /rightOperand ) * 100; - - } else if (pendingOperator == tr("/")) { - if (rightOperand == 0.0) - return false; - factorSoFar = (factorSoFar / 100) * rightOperand; - - } - return true; -} - - -void MiniCalc::percentClicked() -{ - double operand = display->text().toDouble(); - - if (!pendingMultiplicativeOperator.isEmpty()) { - if (!calcpercent(operand, pendingMultiplicativeOperator)) { - abortOperation(); - return; - } - operand = factorSoFar; - factorSoFar = 0.0; - pendingMultiplicativeOperator.truncate( 0 ); - } - - if (!pendingAdditiveOperator.isEmpty()) { - if (!calcpercent(operand, pendingAdditiveOperator)) { - abortOperation(); - return; - } - pendingAdditiveOperator.truncate(0); - } else { - sumSoFar = operand; - } - - display->setText(QString::number(sumSoFar)); - sumSoFar = 0.0; - waitingForOperand = true; - -} - diff --git a/src/ananas/aminicalc.h b/src/ananas/aminicalc.h deleted file mode 100644 index f5c8840..0000000 --- a/src/ananas/aminicalc.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** Form interface generated from reading ui file 'aminicalc.ui' -** -** Created: 2008-06-18T13:52:59 -** -** WARNING! All changes made in this file will be lost! -****************************************************************************/ - -#ifndef MINICALC_H -#define MINICALC_H - -#include -#include - -class QVBoxLayout; -class QHBoxLayout; -class QGridLayout; -class QSpacerItem; -class QFrame; -class QPushButton; -class QLineEdit; -class QLabel; - -class MiniCalc : public QDialog -{ - Q_OBJECT - -public: - MiniCalc( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); - ~MiniCalc(); - - void abortOperation(); - bool calculate(double rightOperand, const QString &pendingOperator); - bool calcpercent(double rightOperand, const QString &pendingOperator); - - double sumInMemory; - double sumSoFar; - double factorSoFar; - QString pendingAdditiveOperator; - QString pendingMultiplicativeOperator; - bool waitingForOperand; - - QFrame* calcFrame; - QPushButton* extMem; - QLineEdit* display; - QPushButton* toDocButton; - QPushButton* clearMemoryButton; - QPushButton* btn_7; - QPushButton* btn_8; - QPushButton* btn_9; - QPushButton* plusButton; - QPushButton* changeSignButton; - QPushButton* clearButton; - QPushButton* readMemoryButton; - QPushButton* btn_4; - QPushButton* btn_5; - QPushButton* btn_6; - QPushButton* minusButton; - QPushButton* persentButton; - QPushButton* clearAllButton; - QPushButton* minusMemoryButton; - QPushButton* btn_1; - QPushButton* btn_2; - QPushButton* btn_3; - QPushButton* timesButton; - QPushButton* reciprocalButton; - QPushButton* backspaceButton; - QPushButton* addToMemoryButton; - QPushButton* btn_0; - QPushButton* doubleZero; - QPushButton* pointButton; - QPushButton* divisionButton; - QPushButton* powButton; - QPushButton* equalButton; - QFrame* extension; - QLabel* label; - QLineEdit* mem_1; - QPushButton* mem_to_disp_4; - QPushButton* disp_to_mem_4; - QPushButton* mem_to_disp_3; - QPushButton* disp_to_mem_3; - QPushButton* disp_to_mem_1; - QLineEdit* mem_4; - QLineEdit* mem_3; - QPushButton* disp_to_mem_2; - QLineEdit* mem_2; - QPushButton* mem_to_disp_2; - QPushButton* mem_to_disp_1; - -public slots: - virtual void digitClicked(); - virtual void unaryOperatorClicked(); - virtual void additiveOperatorClicked(); - virtual void multiplicativeOperatorClicked(); - virtual void equalClicked(); - virtual void dzClicked(); - virtual void pointClicked(); - virtual void percentClicked(); - virtual void changeSignClicked(); - virtual void backspaceClicked(); - virtual void clear(); - virtual void clearAll(); - virtual void clearMemory(); - virtual void readMemory(); - virtual void minusMemory(); - virtual void addToMemory(); - virtual void toDoc(); - virtual void extMemClicked(); - virtual void extMemOperations(); - -protected: - QGridLayout* MiniCalcLayout; - QGridLayout* calcFrameLayout; - QGridLayout* extensionLayout; - -protected slots: - virtual void languageChange(); - -}; - -#endif // MINICALC_H diff --git a/src/ananas/ananas.pro b/src/ananas/ananas.pro index e9a7575..9888838 100644 --- a/src/ananas/ananas.pro +++ b/src/ananas/ananas.pro @@ -3,10 +3,8 @@ TARGET = ananas include ( ../ananas.pri ) SOURCES += main.cpp \ - ananasmainform.cpp \ - aminicalc.cpp -HEADERS += ananasmainform.h \ - aminicalc.h + ananasmainform.cpp +HEADERS += ananasmainform.h #load(qsa) @@ -29,7 +27,8 @@ INSTALLS += ananas #FORMS = qadocjournal.ui IMAGES = images/a-system.png \ - images/calc.png \ + images/calc.png \ + images/calendar.png \ images/msg_info.png \ images/msg_warning.png \ images/msg_error.png \ diff --git a/src/ananas/ananasmainform.cpp b/src/ananas/ananasmainform.cpp index 1fec864..6a72de1 100644 --- a/src/ananas/ananasmainform.cpp +++ b/src/ananas/ananasmainform.cpp @@ -41,6 +41,7 @@ #include "ananas.h" #include "aminicalc.h" +#include "ananas.h" MainForm *mainform=NULL; QWorkspace *mainformws=NULL; @@ -132,6 +133,7 @@ MainForm::initMenuBar() this, SLOT( windowsMenuAboutToShow() ) ); m->insertItem(rcIcon("ananas-32x32.png"), tr( "About" ), this, SLOT( helpAbout() ), Key_F11); s->insertItem(rcIcon("calc.png"), tr( "Calculator" ), this, SLOT( miniCalc() ), Key_F10); + s->insertItem(rcIcon("calendar.png"), tr( "Calendar" ), this, SLOT( ShowCalendar() ), Key_F12); //windowsMenu->insertItem(rcIcon("ananas-32x32.png"), tr( "Windows" ), this, SLOT( windowsMenuAboutToShow() )); menubar = new AMenuBar( md, this, "menubar"); InsertMainMenu( tr("&Tools"), s ); @@ -322,3 +324,14 @@ MainForm::miniCalc() MiniCalc *calc = new MiniCalc(ws, "MiniCalc", false, 0); calc->show(); } + +/* + * Open a Calendar + */ +void +MainForm::ShowCalendar() +{ + PopupCalendar *calendar = new PopupCalendar(QDate::currentDate(), + QPoint(ws->width() / 2, ws->height() / 2 ), ws, ""); + calendar->show(); +} diff --git a/src/ananas/ananasmainform.h b/src/ananas/ananasmainform.h index 189f614..f4af300 100644 --- a/src/ananas/ananasmainform.h +++ b/src/ananas/ananasmainform.h @@ -46,7 +46,8 @@ #include "atoolbar.h" #include "awindowslist.h" #include "engine.h" - +#include "aminicalc.h" +#include "acalendar.h" class QVBoxLayout; class QHBoxLayout; @@ -76,6 +77,8 @@ public: QPopupMenu *windowsMenu; QWorkspace* ws; aWindowsList* wl; + MiniCalc* calc; + PopupCalendar* calendar; QString rcfile; public slots: @@ -88,6 +91,8 @@ public slots: void Exit(int code); void close(); void helpAbout(); + void miniCalc(); + void ShowCalendar(); void statusMessage( const QString &msg ); void windowsMenuAboutToShow(); void windowsMenuActivated( int id ); diff --git a/src/ananas/images/calendar.png b/src/ananas/images/calendar.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1f8455aa10a2c8e42933d647b8bb43c48d0f40 GIT binary patch literal 1385 zcmV-v1(y1WP)%SID7-RTf5=Vbg1*UgR*Y?-O$_D~JH|u-$bl|JWVxY!Kc~z(stnAXetLI)j zweS>xy0`Jj)Og|G%+%Q2c+sEDdG2YbYV&D)23Rf9w6%U=pG^%-O z;{lEZwt{x2v**4U1@QRvBfmeodv?nCL`tQcr(E=K6vTr8Z=AhAwc>MgHKG(al=3$1 zw#(d}Nj6#`o5@-Z0M~U(BaUy}dGA}r{L1rp?q=ST4^IY%xBFa9IwChF=?yfC z*W0|mX0dCki0cgSU5jm#K0E6U&j^mU^z<19){mKu2^0OZoi$&*?^M^6U z@aKznnVTtaZKcbn=66snyX=?<==5T`y_EhSc4^$*Y&J8j#*xh z337^kGd0Fa9*!;1+F*>v``vE|-aZG_D!u)4ARV+Ypf$=?`Hz5=rBcuH>~JgO(ftj| z#ejnEp^d>9g8;0z{)+$luQ9b6B8sq#K}!J!1QOSF9yCwhpIFLDJ3Yp}5pKdqAvWA70C6H1eZ?BR& z{w4IxZU$fZDkKR+5y6G?*u8LABPHchsrKy2Z`vbZ1Ov}?iTVSS94<>Kk-Z-77e0?z zTEa9M1Sd}*Z~OzI2>0#tSaI^eb*(xsfqkQ3L_e3yQ7GgQ!jL2>QV6WGXON4Fh<+dI z^sf-z4hR8J#MbdI!$b{B4wFqx)Bp~SfCUTy9NRXnR*NJ}hfS+iF(*!tz5W~0tM8D! z`WkxAUed?s5w+?t)x9xRE)n?tV+}!jU^*V8q;w~(}!UAYRl4jUa z^1*jcasB-^@k)wgH+gurf&jFU)a#S;BVeH4?z9=igF%v}o@GgrG{bdl0KWh7MRwNn zTw884UUHeL1x!!)_?}I;wZ(h?T#9b5tzQbm@Rd==#`Mx8A?ii(o|#=3ogpk6tuv&w z_~K{wa&5WI-0lk7YBqP)R^!#RrAt>XuDr2$`Rc1Lz3|+-0MC5xv!f408y#g@(+$IT zvR38x`Z|sJB$+lyX()OzqIZ4i(v9`gzg)b0`sY9W(bY#e#K-9YI8DoO$yvfBgIT3(vmz{Hf)SCH;rQ{m=Ak-}v^STrT$=Wm$)g96sRPTw4Cq rzK8bOe>n5z*I# +#include +#include +#include +#include +#include +#include +#include + +#include "ananas.h" +#include "alog.h" +#include "acalendar.h" + + +/** + * \ru + * \brief Запрашивает дату у пользователя, показав ему календарик. + * \return дату, указанную пользователем. + * \_ru + */ +QDate +PopupCalendar::getDate(QWidget *parent, const QDate &day, QPoint pos) +{ + PopupCalendar *calendar = new PopupCalendar(day, pos, parent); + calendar->exec(); + QDate date = calendar->day(); + delete calendar; + return date; +} + + +/** + * \ru + * \brief Осуществляет отрисовку календарика, обрабатывая событие PaintEvent виджета PopupCalendar. + * \_ru + */ +void +PopupCalendar::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.setClipRegion(event->region()); + painter.setFont(smallFont); + int w = width();// Ширина окна + int h = height(); // Высота окна + int dayw = w / COLS; // Ширина ячейки + int dayh = h / (ROWS + 2); // Высота ячейки + + QRect rect; + QColor color = colorGroup().light(); + QColor f_color = "red"; + QColor g_color = "green"; + QColor b_color = "blue"; + // Формируем строку с годом и месяцем + painter.fillRect(1, 1, dayw - 2, dayh - 1, color); + painter.drawText(1, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString("<< "), -1, &rect); + painter.fillRect(dayw, 1, dayw - 2, dayh - 1, color); + painter.drawText(dayw, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" < "), -1, &rect); + painter.drawText(dayw*2+1, 1, dayw*3- 1, dayh - 1, AlignHCenter, today.toString("MMM, yyyy"), -1, &rect); + painter.fillRect(w-(dayw*2), 1, dayw - 2, dayh - 1, color); + painter.drawText(w-(dayw*2), 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" > "), -1, &rect); + painter.fillRect(w-dayw, 1, dayw - 2, dayh - 1, color); + painter.drawText(w-dayw, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" >>"), -1, &rect); + +// Формируем строку с днями недели + int i; + int y = dayh; + for (i = 0; i < 7; i++) { + + painter.drawText(dayw * i + 1, y, dayw, dayh - 1, + AlignHCenter, QDate::shortDayName(i+1), -1, &rect); + } + + // Заплняем таблицу календаря + QDate day(today.year(), today.month(), 1); + int day_pos = day.dayOfWeek()-1; + day = day.addDays(-day_pos); + y += dayh; + for (int j = 0; j < ROWS-1; ++j) + for (i = 0; i < COLS; ++i) { + color = (day == today) ? colorGroup().light() : ( ( i < 5 ) ? colorGroup().light() : colorGroup().midlight()); + if (day == today){ + painter.fillRect(dayw * i + 1, dayh * j + y + 1, dayw - 1, dayh - 1, b_color); + painter.fillRect(dayw * i + 3, dayh * j + y + 3, dayw - 5, dayh - 5, color); + }else{ + painter.fillRect(dayw * i + 1, dayh * j + y + 1, dayw - 1, dayh - 1, color); + } + (today.month() != day.month() )? painter.setPen(colorGroup().mid()): ( ( i < 5 ) ? painter.setPen(colorGroup().foreground()):painter.setPen(f_color)); + painter.drawText(dayw * i + 2, dayh * j + y + 2, dayw, dayh, AlignTop|AlignHCenter, day.toString("d")); + day = day.addDays(1); + } + // Формируем последнюю строку + painter.fillRect(1, h - dayh - 1, dayw*2, dayh - 1, b_color); + painter.fillRect(3, h - dayh + 1, dayw*2-4, dayh - 5, color); + painter.setPen(colorGroup().foreground()); + painter.drawText(2, h - dayh, dayw*2-2, dayh - 3, AlignTop|AlignHCenter, "Now"); + painter.drawText(w - dayw*3, h - dayh, dayw*3-2, dayh - 1, AlignTop|AlignHCenter, QString(tr("Week: %1").arg(today.weekNumber()))); +} + +/** + * \ru + * \brief Обрабатывает пользовательские действия по выбору даты в календарике. + * + * Записывает значение выбранной пользователем даты в свойство виджета. + * + * \_ru + */ +void +PopupCalendar::keyPressEvent(QKeyEvent *event) +{ + int days = 0; + switch (event->key()) { + case Key_Left: days = -1; break; + case Key_Right: days = 1; break; + case Key_Up: days = -COLS; break; + case Key_Down: days = COLS; break; + case Key_PageUp: days = today.daysTo(today.addMonths(-1)); break; + case Key_PageDown: days = today.daysTo(today.addMonths(1)); break; + case Key_Home: days = today.daysTo(today.addYears(-1)); break; + case Key_End: days = today.daysTo(today.addYears(1)); break; + case Key_Escape: today = original; accept(); break; + case Key_Space: // fallthrough + case Key_Enter: // fallthrough + case Key_Return: accept(); return; + default: QDialog::keyPressEvent(event); return; + } + + QDate day = today.addDays(days); + if (day != today) + setDay(day); +} + +/** + * \ru + * \brief Обрабатывает пользовательские действия мышкой по выбору даты в календарике. + * Записывает значение выбранной пользователем даты в свойство виджета. + * + * \_ru + */ +void +PopupCalendar::mousePressEvent(QMouseEvent *event) +{ + QDate day = today; + int w = width(); + int h = height(); + int dayh2 = (h / (ROWS + 2)) * 2; + int dayh = h / (ROWS + 2); // Высота строки + int dayw = w / COLS; // Ширина колонки + if (event->y() < dayh) { + if (event->x() > 1 && event->x() < dayw) day = day.addYears(-1); + if (event->x() > dayw && event->x() < dayw*2 ) day = day.addMonths(-1); + if (event->x() > (w - dayw*2) && event->x() < (w - dayw) ) day = day.addMonths(1); + if (event->x() > (w - dayw) ) day = day.addYears(1); + } else { + if (event->y() > dayh2 && event->y() < h - dayh) { + int xday = event->x() / (width() / (COLS) ); + int yday = (event->y() - dayh2) / ((h - dayh2) / ROWS); + day = QDate(today.year(), today.month(), 1); + int day_pos = day.dayOfWeek()-1; + day = day.addDays(xday + (COLS * yday) - (day_pos)); + }else{ + if (event->x() > 1 && event->x() < dayw*2) { + day = today.currentDate(); + } + } + } + if (day != today) setDay(day); +} + +/** + * \ru + * \brief Обрабатывает двойной клик мышкой в календарике. + * + * Записывает значение выбранной пользователем даты в свойство виджета. + * + * \_ru + */ +void +PopupCalendar::mouseDoubleClickEvent(QMouseEvent *event) +{ + QDate day = today; + int w = width(); + int h = height(); + int dayh2 = (h / (ROWS + 2)) * 2; + int dayh = h / (ROWS + 2); // Высота строки + int dayw = w / COLS; // Ширина колонки + + if (event->y() > dayh2 && event->y() < h - dayh) { + int xday = event->x() / (width() / (COLS) ); + int yday = (event->y() - dayh2) / ((h - dayh2) / ROWS); + day = QDate(today.year(), today.month(), 1); + int day_pos = day.dayOfWeek()-1; + day = day.addDays(xday + (COLS * yday) - (day_pos)); + if (day != today) setDay(day); + accept(); + } +} + +QSize +PopupCalendar::sizeHint() const +{ + QFontMetrics fm(smallFont); + return QSize(COLS * (fm.width(tr("Wed"))+2), (ROWS + 2) * fm.height() * 1.2); +} + +/** + * \ru + * \brief Сеттер задающий дату виджету. + * + * Вызывает перерисовку виджета. + * + * \_ru + */ +void +PopupCalendar::setDay(const QDate &day) +{ + today = day; + update(); +} + + +/** + * \ru + * \brief Конструктор. Инициализирует свойства виджета, задает надпись в шапке виджета. + * + * \_ru + */ +PopupCalendar::PopupCalendar(const QDate &day, QPoint pos, + QWidget *parent, const char *name) + : QDialog(parent, name), today(day), original(day) +{ + setCaption(tr("A-Calendar")); + if (!pos.isNull()) move(pos); + smallFont = font(); + if (smallFont.pointSize() >= 10) { + smallFont.setPointSize(smallFont.pointSize() - 2); + smallFont.setBold(true); + } + + setFixedSize(sizeHint()); + setFocusPolicy(StrongFocus); +} diff --git a/src/lib/acalendar.h b/src/lib/acalendar.h new file mode 100644 index 0000000..fcf98e0 --- /dev/null +++ b/src/lib/acalendar.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** $Id: acalendar.h,v 1.37 2008/06/09 11:44:27 dkr Exp $ +** +** +**********************************************************************/ + +#ifndef CALENDAR_H +#define CALENDAR_H + +#include +#include +#include +#include +#include "ananas.h" + +/*! + * \en PopupCalendar for DateEdit field editor. \_en + * \ru + * \brief Всплывающий календарь для выбора даты. + * + * Используется как дополнение к виджету поля ввода/редактирования + * атрибута типа Дата бизнес объекта Ананаса. + * + * \_ru + */ +class PopupCalendar : public QDialog +{ +Q_OBJECT +public: + PopupCalendar(const QDate &day = QDate::currentDate(), + QPoint pos = QPoint(), QWidget *parent = 0, const char *name = 0); + + static QDate getDate(QWidget *parent = 0, const QDate &day = QDate::currentDate(), + QPoint pos = QPoint()); + + const QDate& day() const { return today; } + void setDay(const QDate &day); + QSize sizeHint() const; + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + void paintEvent(QPaintEvent *event); + +private: + enum { ROWS = 7, COLS = 7 }; + QFont smallFont; + QDate today; + const QDate original; +}; + +#endif diff --git a/src/lib/aminicalc.cpp b/src/lib/aminicalc.cpp new file mode 100644 index 0000000..769f294 --- /dev/null +++ b/src/lib/aminicalc.cpp @@ -0,0 +1,927 @@ +/**************************************************************************** +** Form implementation generated from reading ui file 'aminicalc.ui' +** +** Created: 2008-06-18T13:53:05 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "aminicalc.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Constructs a MiniCalc as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +MiniCalc::MiniCalc( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) setName( "MiniCalc" ); + setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 1, 1, sizePolicy().hasHeightForWidth() ) ); + MiniCalcLayout = new QGridLayout( this, 1, 1, 1, 1, "MiniCalcLayout"); + MiniCalcLayout->setResizeMode( QLayout::Fixed ); + + sumInMemory = 0.0; + sumSoFar = 0.0; + factorSoFar = 0.0; + waitingForOperand = true; + + + calcFrame = new QFrame( this, "calcFrame" ); + calcFrame->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, calcFrame->sizePolicy().hasHeightForWidth() ) ); + calcFrame->setFrameShape( QFrame::StyledPanel ); + calcFrame->setFrameShadow( QFrame::Raised ); + calcFrameLayout = new QGridLayout( calcFrame, 1, 1, 1, 1, "calcFrameLayout"); + + extMem = new QPushButton( calcFrame, "extMem" ); + extMem->setMaximumSize( QSize( 25, 25 ) ); + extMem->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); + QFont extMem_font( extMem->font() ); + extMem_font.setPointSize( 8 ); + extMem->setFont( extMem_font ); + extMem->setToggleButton( TRUE ); + + calcFrameLayout->addWidget( extMem, 0, 0 ); + + display = new QLineEdit( calcFrame, "display" ); + QFont display_font( display->font() ); + display_font.setFamily( "xos4 Terminus" ); + display_font.setPointSize( 11 ); + display->setFont( display_font ); + display->setText("0"); + display->setReadOnly(true); + display->setAlignment(Qt::AlignRight); + display->setMaxLength(15); + display->installEventFilter(this); + + + calcFrameLayout->addMultiCellWidget( display, 0, 0, 1, 5 ); + + toDocButton = new QPushButton( calcFrame, "toDocButton" ); + toDocButton->setMaximumSize( QSize( 25, 25 ) ); + toDocButton->setPaletteBackgroundColor( QColor( 200, 200, 250 ) ); + QFont toDocButton_font( toDocButton->font() ); + toDocButton_font.setPointSize( 8 ); + toDocButton->setFont( toDocButton_font ); + + calcFrameLayout->addWidget( toDocButton, 0, 6 ); + + clearMemoryButton = new QPushButton( calcFrame, "clearMemoryButton" ); + clearMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearMemoryButton->sizePolicy().hasHeightForWidth() ) ); + clearMemoryButton->setMaximumSize( QSize( 25, 25 ) ); + clearMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); + QFont clearMemoryButton_font( clearMemoryButton->font() ); + clearMemoryButton_font.setPointSize( 8 ); + clearMemoryButton->setFont( clearMemoryButton_font ); + + calcFrameLayout->addWidget( clearMemoryButton, 1, 0 ); + + btn_7 = new QPushButton( calcFrame, "btn_7" ); + btn_7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_7->sizePolicy().hasHeightForWidth() ) ); + btn_7->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_7_font( btn_7->font() ); + btn_7_font.setPointSize( 8 ); + btn_7->setFont( btn_7_font ); + + calcFrameLayout->addWidget( btn_7, 1, 1 ); + + btn_8 = new QPushButton( calcFrame, "btn_8" ); + btn_8->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_8->sizePolicy().hasHeightForWidth() ) ); + btn_8->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_8_font( btn_8->font() ); + btn_8_font.setPointSize( 8 ); + btn_8->setFont( btn_8_font ); + + calcFrameLayout->addWidget( btn_8, 1, 2 ); + + btn_9 = new QPushButton( calcFrame, "btn_9" ); + btn_9->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_9->sizePolicy().hasHeightForWidth() ) ); + btn_9->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_9_font( btn_9->font() ); + btn_9_font.setPointSize( 8 ); + btn_9->setFont( btn_9_font ); + + calcFrameLayout->addWidget( btn_9, 1, 3 ); + + plusButton = new QPushButton( calcFrame, "plusButton" ); + plusButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, plusButton->sizePolicy().hasHeightForWidth() ) ); + plusButton->setMaximumSize( QSize( 25, 25 ) ); + plusButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont plusButton_font( plusButton->font() ); + plusButton_font.setPointSize( 8 ); + plusButton->setFont( plusButton_font ); + + calcFrameLayout->addWidget( plusButton, 1, 4 ); + + changeSignButton = new QPushButton( calcFrame, "changeSignButton" ); + changeSignButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, changeSignButton->sizePolicy().hasHeightForWidth() ) ); + changeSignButton->setMaximumSize( QSize( 25, 25 ) ); + changeSignButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont changeSignButton_font( changeSignButton->font() ); + changeSignButton_font.setPointSize( 8 ); + changeSignButton->setFont( changeSignButton_font ); + + calcFrameLayout->addWidget( changeSignButton, 1, 5 ); + + clearButton = new QPushButton( calcFrame, "clearButton" ); + clearButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearButton->sizePolicy().hasHeightForWidth() ) ); + clearButton->setMaximumSize( QSize( 25, 25 ) ); + clearButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); + QFont clearButton_font( clearButton->font() ); + clearButton_font.setPointSize( 8 ); + clearButton->setFont( clearButton_font ); + + calcFrameLayout->addWidget( clearButton, 1, 6 ); + + readMemoryButton = new QPushButton( calcFrame, "readMemoryButton" ); + readMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, readMemoryButton->sizePolicy().hasHeightForWidth() ) ); + readMemoryButton->setMaximumSize( QSize( 25, 25 ) ); + readMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); + QFont readMemoryButton_font( readMemoryButton->font() ); + readMemoryButton_font.setPointSize( 8 ); + readMemoryButton->setFont( readMemoryButton_font ); + + calcFrameLayout->addWidget( readMemoryButton, 2, 0 ); + + btn_4 = new QPushButton( calcFrame, "btn_4" ); + btn_4->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_4->sizePolicy().hasHeightForWidth() ) ); + btn_4->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_4_font( btn_4->font() ); + btn_4_font.setPointSize( 8 ); + btn_4->setFont( btn_4_font ); + + calcFrameLayout->addWidget( btn_4, 2, 1 ); + + btn_5 = new QPushButton( calcFrame, "btn_5" ); + btn_5->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_5->sizePolicy().hasHeightForWidth() ) ); + btn_5->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_5_font( btn_5->font() ); + btn_5_font.setPointSize( 8 ); + btn_5->setFont( btn_5_font ); + + calcFrameLayout->addWidget( btn_5, 2, 2 ); + + btn_6 = new QPushButton( calcFrame, "btn_6" ); + btn_6->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_6->sizePolicy().hasHeightForWidth() ) ); + btn_6->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_6_font( btn_6->font() ); + btn_6_font.setPointSize( 8 ); + btn_6->setFont( btn_6_font ); + + calcFrameLayout->addWidget( btn_6, 2, 3 ); + + minusButton = new QPushButton( calcFrame, "minusButton" ); + minusButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, minusButton->sizePolicy().hasHeightForWidth() ) ); + minusButton->setMaximumSize( QSize( 25, 25 ) ); + minusButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont minusButton_font( minusButton->font() ); + minusButton_font.setPointSize( 8 ); + minusButton->setFont( minusButton_font ); + + calcFrameLayout->addWidget( minusButton, 2, 4 ); + + persentButton = new QPushButton( calcFrame, "persentButton" ); + persentButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, persentButton->sizePolicy().hasHeightForWidth() ) ); + persentButton->setMaximumSize( QSize( 25, 25 ) ); + persentButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont persentButton_font( persentButton->font() ); + persentButton_font.setPointSize( 8 ); + persentButton->setFont( persentButton_font ); + + calcFrameLayout->addWidget( persentButton, 2, 5 ); + + clearAllButton = new QPushButton( calcFrame, "clearAllButton" ); + clearAllButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, clearAllButton->sizePolicy().hasHeightForWidth() ) ); + clearAllButton->setMaximumSize( QSize( 25, 25 ) ); + clearAllButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); + QFont clearAllButton_font( clearAllButton->font() ); + clearAllButton_font.setPointSize( 8 ); + clearAllButton->setFont( clearAllButton_font ); + + calcFrameLayout->addWidget( clearAllButton, 2, 6 ); + + minusMemoryButton = new QPushButton( calcFrame, "minusMemoryButton" ); + minusMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, minusMemoryButton->sizePolicy().hasHeightForWidth() ) ); + minusMemoryButton->setMaximumSize( QSize( 25, 25 ) ); + minusMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); + QFont minusMemoryButton_font( minusMemoryButton->font() ); + minusMemoryButton_font.setPointSize( 8 ); + minusMemoryButton->setFont( minusMemoryButton_font ); + + calcFrameLayout->addWidget( minusMemoryButton, 3, 0 ); + + btn_1 = new QPushButton( calcFrame, "btn_1" ); + btn_1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_1->sizePolicy().hasHeightForWidth() ) ); + btn_1->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_1_font( btn_1->font() ); + btn_1_font.setPointSize( 8 ); + btn_1->setFont( btn_1_font ); + + calcFrameLayout->addWidget( btn_1, 3, 1 ); + + btn_2 = new QPushButton( calcFrame, "btn_2" ); + btn_2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_2->sizePolicy().hasHeightForWidth() ) ); + btn_2->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_2_font( btn_2->font() ); + btn_2_font.setPointSize( 8 ); + btn_2->setFont( btn_2_font ); + + calcFrameLayout->addWidget( btn_2, 3, 2 ); + + btn_3 = new QPushButton( calcFrame, "btn_3" ); + btn_3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_3->sizePolicy().hasHeightForWidth() ) ); + btn_3->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_3_font( btn_3->font() ); + btn_3_font.setPointSize( 8 ); + btn_3->setFont( btn_3_font ); + + calcFrameLayout->addWidget( btn_3, 3, 3 ); + + timesButton = new QPushButton( calcFrame, "timesButton" ); + timesButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, timesButton->sizePolicy().hasHeightForWidth() ) ); + timesButton->setMaximumSize( QSize( 25, 25 ) ); + timesButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont timesButton_font( timesButton->font() ); + timesButton_font.setPointSize( 8 ); + timesButton->setFont( timesButton_font ); + + calcFrameLayout->addWidget( timesButton, 3, 4 ); + + reciprocalButton = new QPushButton( calcFrame, "reciprocalButton" ); + reciprocalButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, reciprocalButton->sizePolicy().hasHeightForWidth() ) ); + reciprocalButton->setMaximumSize( QSize( 25, 25 ) ); + reciprocalButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont reciprocalButton_font( reciprocalButton->font() ); + reciprocalButton_font.setPointSize( 8 ); + reciprocalButton->setFont( reciprocalButton_font ); + + calcFrameLayout->addWidget( reciprocalButton, 3, 5 ); + + backspaceButton = new QPushButton( calcFrame, "backspaceButton" ); + backspaceButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, backspaceButton->sizePolicy().hasHeightForWidth() ) ); + backspaceButton->setMaximumSize( QSize( 25, 25 ) ); + backspaceButton->setPaletteBackgroundColor( QColor( 250, 200, 200 ) ); + QFont backspaceButton_font( backspaceButton->font() ); + backspaceButton_font.setPointSize( 8 ); + backspaceButton->setFont( backspaceButton_font ); + + calcFrameLayout->addWidget( backspaceButton, 3, 6 ); + + addToMemoryButton = new QPushButton( calcFrame, "addToMemoryButton" ); + addToMemoryButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, addToMemoryButton->sizePolicy().hasHeightForWidth() ) ); + addToMemoryButton->setMaximumSize( QSize( 25, 25 ) ); + addToMemoryButton->setPaletteBackgroundColor( QColor( 205, 205, 205 ) ); + QFont addToMemoryButton_font( addToMemoryButton->font() ); + addToMemoryButton_font.setPointSize( 8 ); + addToMemoryButton->setFont( addToMemoryButton_font ); + + calcFrameLayout->addWidget( addToMemoryButton, 4, 0 ); + + btn_0 = new QPushButton( calcFrame, "btn_0" ); + btn_0->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, btn_0->sizePolicy().hasHeightForWidth() ) ); + btn_0->setMaximumSize( QSize( 25, 25 ) ); + QFont btn_0_font( btn_0->font() ); + btn_0_font.setPointSize( 8 ); + btn_0->setFont( btn_0_font ); + + calcFrameLayout->addWidget( btn_0, 4, 1 ); + + doubleZero = new QPushButton( calcFrame, "doubleZero" ); + doubleZero->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, doubleZero->sizePolicy().hasHeightForWidth() ) ); + doubleZero->setMaximumSize( QSize( 25, 25 ) ); + QFont doubleZero_font( doubleZero->font() ); + doubleZero_font.setPointSize( 8 ); + doubleZero->setFont( doubleZero_font ); + + calcFrameLayout->addWidget( doubleZero, 4, 2 ); + + pointButton = new QPushButton( calcFrame, "pointButton" ); + pointButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, pointButton->sizePolicy().hasHeightForWidth() ) ); + pointButton->setMaximumSize( QSize( 25, 25 ) ); + QFont pointButton_font( pointButton->font() ); + pointButton_font.setPointSize( 8 ); + pointButton->setFont( pointButton_font ); + + calcFrameLayout->addWidget( pointButton, 4, 3 ); + + divisionButton = new QPushButton( calcFrame, "divisionButton" ); + divisionButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, divisionButton->sizePolicy().hasHeightForWidth() ) ); + divisionButton->setMaximumSize( QSize( 25, 25 ) ); + divisionButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont divisionButton_font( divisionButton->font() ); + divisionButton_font.setPointSize( 8 ); + divisionButton->setFont( divisionButton_font ); + + calcFrameLayout->addWidget( divisionButton, 4, 4 ); + + powButton = new QPushButton( calcFrame, "powButton" ); + powButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, powButton->sizePolicy().hasHeightForWidth() ) ); + powButton->setMaximumSize( QSize( 25, 25 ) ); + powButton->setPaletteBackgroundColor( QColor( 200, 250, 200 ) ); + QFont powButton_font( powButton->font() ); + powButton_font.setPointSize( 8 ); + powButton->setFont( powButton_font ); + + calcFrameLayout->addWidget( powButton, 4, 5 ); + + equalButton = new QPushButton( calcFrame, "equalButton" ); + equalButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, equalButton->sizePolicy().hasHeightForWidth() ) ); + equalButton->setMaximumSize( QSize( 25, 25 ) ); + equalButton->setPaletteBackgroundColor( QColor( 200, 200, 250 ) ); + QFont equalButton_font( equalButton->font() ); + equalButton_font.setPointSize( 8 ); + equalButton->setFont( equalButton_font ); + + calcFrameLayout->addWidget( equalButton, 4, 6 ); + + MiniCalcLayout->addWidget( calcFrame, 0, 0 ); + + extension = new QFrame( this, "extension" ); + extension->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, extension->sizePolicy().hasHeightForWidth() ) ); + extension->setFrameShape( QFrame::StyledPanel ); + extension->setFrameShadow( QFrame::Raised ); + extensionLayout = new QGridLayout( extension, 1, 1, 1, 1, "extensionLayout"); + + label = new QLabel( extension, "label" ); + label->setMinimumSize( QSize( 0, 20 ) ); + QFont label_font( label->font() ); + label_font.setPointSize( 8 ); + label->setFont( label_font ); + //label->setAlignment( int( QLabel::AlignCenter ) ); + + extensionLayout->addMultiCellWidget( label, 0, 0, 0, 2 ); + + mem_1 = new QLineEdit( extension, "mem_1" ); + QFont mem_1_font( mem_1->font() ); + mem_1_font.setPointSize( 10 ); + mem_1->setFont( mem_1_font ); + + extensionLayout->addWidget( mem_1, 1, 2 ); + + mem_to_disp_4 = new QPushButton( extension, "mtd_4" ); + mem_to_disp_4->setMaximumSize( QSize( 25, 25 ) ); + QFont mem_to_disp_4_font( mem_to_disp_4->font() ); + mem_to_disp_4_font.setPointSize( 8 ); + mem_to_disp_4->setFont( mem_to_disp_4_font ); + + extensionLayout->addWidget( mem_to_disp_4, 4, 1 ); + + disp_to_mem_4 = new QPushButton( extension, "dtm_4" ); + disp_to_mem_4->setMaximumSize( QSize( 25, 25 ) ); + QFont disp_to_mem_4_font( disp_to_mem_4->font() ); + disp_to_mem_4_font.setPointSize( 8 ); + disp_to_mem_4->setFont( disp_to_mem_4_font ); + + extensionLayout->addWidget( disp_to_mem_4, 4, 0 ); + + mem_to_disp_3 = new QPushButton( extension, "mtd_3" ); + mem_to_disp_3->setMaximumSize( QSize( 25, 25 ) ); + QFont mem_to_disp_3_font( mem_to_disp_3->font() ); + mem_to_disp_3_font.setPointSize( 8 ); + mem_to_disp_3->setFont( mem_to_disp_3_font ); + + extensionLayout->addWidget( mem_to_disp_3, 3, 1 ); + + disp_to_mem_3 = new QPushButton( extension, "dtm_3" ); + disp_to_mem_3->setMaximumSize( QSize( 25, 25 ) ); + QFont disp_to_mem_3_font( disp_to_mem_3->font() ); + disp_to_mem_3_font.setPointSize( 8 ); + disp_to_mem_3->setFont( disp_to_mem_3_font ); + + extensionLayout->addWidget( disp_to_mem_3, 3, 0 ); + + disp_to_mem_1 = new QPushButton( extension, "dtm_1" ); + disp_to_mem_1->setMaximumSize( QSize( 25, 25 ) ); + QFont disp_to_mem_1_font( disp_to_mem_1->font() ); + disp_to_mem_1_font.setPointSize( 8 ); + disp_to_mem_1->setFont( disp_to_mem_1_font ); + + extensionLayout->addWidget( disp_to_mem_1, 1, 0 ); + + mem_4 = new QLineEdit( extension, "mem_4" ); + QFont mem_4_font( mem_4->font() ); + mem_4_font.setPointSize( 10 ); + mem_4->setFont( mem_4_font ); + + extensionLayout->addWidget( mem_4, 4, 2 ); + + mem_3 = new QLineEdit( extension, "mem_3" ); + QFont mem_3_font( mem_3->font() ); + mem_3_font.setPointSize( 10 ); + mem_3->setFont( mem_3_font ); + + extensionLayout->addWidget( mem_3, 3, 2 ); + + disp_to_mem_2 = new QPushButton( extension, "dtm_2" ); + disp_to_mem_2->setMaximumSize( QSize( 25, 25 ) ); + QFont disp_to_mem_2_font( disp_to_mem_2->font() ); + disp_to_mem_2_font.setPointSize( 8 ); + disp_to_mem_2->setFont( disp_to_mem_2_font ); + + extensionLayout->addWidget( disp_to_mem_2, 2, 0 ); + + mem_2 = new QLineEdit( extension, "mem_2" ); + QFont mem_2_font( mem_2->font() ); + mem_2_font.setPointSize( 10 ); + mem_2->setFont( mem_2_font ); + + extensionLayout->addWidget( mem_2, 2, 2 ); + + mem_to_disp_2 = new QPushButton( extension, "mtd_2" ); + mem_to_disp_2->setMaximumSize( QSize( 25, 25 ) ); + QFont mem_to_disp_2_font( mem_to_disp_2->font() ); + mem_to_disp_2_font.setPointSize( 8 ); + mem_to_disp_2->setFont( mem_to_disp_2_font ); + + extensionLayout->addWidget( mem_to_disp_2, 2, 1 ); + + mem_to_disp_1 = new QPushButton( extension, "mtd_1" ); + mem_to_disp_1->setMaximumSize( QSize( 25, 25 ) ); + QFont mem_to_disp_1_font( mem_to_disp_1->font() ); + mem_to_disp_1_font.setPointSize( 8 ); + mem_to_disp_1->setFont( mem_to_disp_1_font ); + + extensionLayout->addWidget( mem_to_disp_1, 1, 1 ); + + MiniCalcLayout->addWidget( extension, 1, 0 ); + languageChange(); + resize( QSize(210, 233).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + extension->hide(); + clearMemoryButton->setDisabled(true); + readMemoryButton->setDisabled(true); + + // signals and slots connections + connect( extMem, SIGNAL( clicked() ), this, SLOT( extMemClicked() ) ); + connect( btn_0, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_1, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_2, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_3, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_4, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_5, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_6, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_7, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_8, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( btn_9, SIGNAL( clicked() ), this, SLOT( digitClicked() ) ); + connect( mem_to_disp_1, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( mem_to_disp_2, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( mem_to_disp_3, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( mem_to_disp_4, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( disp_to_mem_1, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( disp_to_mem_2, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( disp_to_mem_3, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( disp_to_mem_4, SIGNAL( clicked() ), this, SLOT(extMemOperations())); + connect( backspaceButton, SIGNAL( clicked() ), this, SLOT(backspaceClicked())); + connect( changeSignButton, SIGNAL( clicked() ), this, SLOT(changeSignClicked())); + connect( reciprocalButton, SIGNAL( clicked() ), this, SLOT( unaryOperatorClicked() ) ); + connect( powButton, SIGNAL( clicked() ), this, SLOT( unaryOperatorClicked() ) ); + connect( divisionButton, SIGNAL( clicked() ), this, SLOT( multiplicativeOperatorClicked() ) ); + connect( timesButton, SIGNAL( clicked() ), this, SLOT( multiplicativeOperatorClicked() ) ); + connect( minusButton, SIGNAL( clicked() ), this, SLOT( additiveOperatorClicked() ) ); + connect( plusButton, SIGNAL( clicked() ), this, SLOT( additiveOperatorClicked() ) ); + connect( persentButton, SIGNAL( clicked() ), this, SLOT( percentClicked() ) ); + connect( equalButton, SIGNAL( clicked() ), this, SLOT( equalClicked() ) ); + connect( doubleZero, SIGNAL( clicked() ), this, SLOT( dzClicked() ) ); + connect( pointButton, SIGNAL( clicked() ), this, SLOT( pointClicked() ) ); + connect( clearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); + connect( clearAllButton, SIGNAL( clicked() ), this, SLOT( clearAll() ) ); + connect( clearMemoryButton, SIGNAL( clicked() ), this, SLOT( clearMemory() ) ); + connect( toDocButton, SIGNAL( clicked() ), this, SLOT( toDoc() ) ); + connect( clearMemoryButton, SIGNAL( clicked() ), this, SLOT( clearMemory() ) ); + connect( readMemoryButton, SIGNAL( clicked() ), this, SLOT( readMemory() ) ); + connect( minusMemoryButton, SIGNAL( clicked() ), this, SLOT( minusMemory() ) ); + connect( addToMemoryButton, SIGNAL( clicked() ), this, SLOT( addToMemory() ) ); + +} + +/* + * Destroys the object and frees any allocated resources + */ +MiniCalc::~MiniCalc() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void MiniCalc::languageChange() +{ + setCaption( tr( "A-Calc" ) ); + extMem->setText( tr( "ME" ) ); + toDocButton->setText( tr( "->" ) ); + clearMemoryButton->setText( tr( "MC" ) ); + btn_7->setText( tr( "7" ) ); + btn_8->setText( tr( "8" ) ); + btn_9->setText( tr( "9" ) ); + plusButton->setText( tr( "+" ) ); + changeSignButton->setText( tr( "\261" ) ); + clearButton->setText( tr( "C" ) ); + readMemoryButton->setText( tr( "MR" ) ); + btn_4->setText( tr( "4" ) ); + btn_5->setText( tr( "5" ) ); + btn_6->setText( tr( "6" ) ); + minusButton->setText( tr( "-" ) ); + persentButton->setText( tr( "%" ) ); + clearAllButton->setText( tr( "CE" ) ); + minusMemoryButton->setText( tr( "M-" ) ); + btn_1->setText( tr( "1" ) ); + btn_2->setText( tr( "2" ) ); + btn_3->setText( tr( "3" ) ); + timesButton->setText( tr( "\327" ) ); + reciprocalButton->setText( tr( "1/X" ) ); + backspaceButton->setText( tr( "<-" ) ); + addToMemoryButton->setText( tr( "M+" ) ); + btn_0->setText( tr( "0" ) ); + doubleZero->setText( tr( "00" ) ); + pointButton->setText( tr( "." ) ); + divisionButton->setText( tr( "/" ) ); + powButton->setText( tr( "x\262" ) ); + equalButton->setText( tr( "=" ) ); + label->setText( tr( "In memory: 0" ) ); + mem_to_disp_4->setText( tr( "<" ) ); + disp_to_mem_4->setText( tr( ">" ) ); + mem_to_disp_3->setText( tr( "<" ) ); + disp_to_mem_3->setText( tr( ">" ) ); + disp_to_mem_1->setText( tr( ">" ) ); + disp_to_mem_2->setText( tr( ">" ) ); + mem_to_disp_2->setText( tr( "<" ) ); + mem_to_disp_1->setText( tr( "<" ) ); +} + + +/* + * Open a extended memory cells + */ +void MiniCalc::extMemClicked() +{ + if ( !extension->isVisibleTo(0) ) { + extension->show(); + setCaption( tr( "A-Calc +" ) ); + } else { + extension->hide(); + setCaption( tr( "A-Calc" ) ); + } + return; +} + + +void MiniCalc::digitClicked() +{ + QPushButton *clickedButton = (QPushButton*)sender(); + int digitValue = clickedButton->text().toInt(); + if (display->text() == "0" && digitValue == 0.0) + return; + + if (waitingForOperand) { + display->clear(); + waitingForOperand = false; + } + display->setText(display->text() + QString::number(digitValue)); + +} + + +void MiniCalc::dzClicked() +{ + double operand = display->text().toDouble(); + double result = 0.0; + if (operand > 0.0) { + result = operand * 100; + display->setText(QString::number(result)); + } + else {return;} +} + +void MiniCalc::unaryOperatorClicked() +{ + QPushButton *clickedButton = (QPushButton*)sender(); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + double result = 0.0; + + + if (clickedOperator == tr("x\262")) { + result = pow(operand, 2.0); + } else if (clickedOperator == tr("1/X")) { + if (operand == 0.0) { + abortOperation(); + return; + } + result = 1.0 / operand; + } + display->setText(QString::number(result)); + waitingForOperand = true; +} + + +void MiniCalc::additiveOperatorClicked() +{ + QPushButton *clickedButton = (QPushButton*)sender(); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.truncate(0); + } + + if (!pendingAdditiveOperator.isEmpty()) { + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(sumSoFar)); + } else { + sumSoFar = operand; + } + + pendingAdditiveOperator = clickedOperator; + waitingForOperand = true; +} + + +void MiniCalc::multiplicativeOperatorClicked() +{ + QPushButton *clickedButton = (QPushButton*)sender(); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + } else { + factorSoFar = operand; + } + + pendingMultiplicativeOperator = clickedOperator; + waitingForOperand = true; +} + + +void MiniCalc::pointClicked() +{ + if (waitingForOperand) + display->setText("0"); + if (!display->text().contains(".")) + display->setText(display->text() + tr(".")); + waitingForOperand = false; +} + + +void MiniCalc::changeSignClicked() +{ + QString text = display->text(); + double value = text.toDouble(); + + if (value > 0.0) { + text.prepend(tr("-")); + } else if (value < 0.0) { + text.remove(0, 1); + } + display->setText(text); +} + + +void MiniCalc::backspaceClicked() +{ + if (waitingForOperand) return; + + QString text = display->text(); + display->end(false); + display->backspace(); + if (text.isEmpty()) { + text = "0"; + waitingForOperand = true; + display->setText(text); + } + +} + + +void MiniCalc::clear() +{ + if (waitingForOperand) return; + display->setText("0"); + waitingForOperand = true; +} + + +void MiniCalc::clearAll() +{ + sumSoFar = 0.0; + factorSoFar = 0.0; + pendingAdditiveOperator.truncate(0); + pendingMultiplicativeOperator.truncate(0); + display->setText("0"); + waitingForOperand = true; +} + + +void MiniCalc::clearMemory() +{ + sumInMemory = 0.0; + clearMemoryButton->setDisabled(true); + readMemoryButton->setDisabled(true); + label->setText(QString("In memory: %1").arg(sumInMemory)); +} + +/* +* Return calculated value to Document +*/ +void MiniCalc::toDoc() +{ +// Sorry, later... +} + + +void MiniCalc::readMemory() +{ + display->setText(QString::number(sumInMemory)); + waitingForOperand = true; +} + + +void MiniCalc::minusMemory() +{ + equalClicked(); + sumInMemory -= display->text().toDouble(); + clearMemoryButton->setEnabled(true); + readMemoryButton->setEnabled(true); + label->setText(QString("In memory: %1").arg(sumInMemory)); +} + + +void MiniCalc::addToMemory() +{ + equalClicked(); + sumInMemory += display->text().toDouble(); + clearMemoryButton->setEnabled(true); + readMemoryButton->setEnabled(true); + label->setText(QString("In memory: %1").arg(sumInMemory)); +} + + +void MiniCalc::abortOperation() +{ + clearAll(); + display->setText(tr("ERROR")); +} + + +bool MiniCalc::calculate(double rightOperand, const QString &pendingOperator) +{ + if (pendingOperator == tr("+")) { + sumSoFar += rightOperand; + } else if (pendingOperator == tr("-")) { + sumSoFar -= rightOperand; + } else if (pendingOperator == tr("\327")) { + factorSoFar *= rightOperand; + } else if (pendingOperator == tr("/")) { + if (rightOperand == 0.0) + return false; + factorSoFar /= rightOperand; + } + return true; +} + + +void MiniCalc::extMemOperations() +{ + QPushButton *clickedButton = (QPushButton*)sender(); + QString clickedOperator = clickedButton->name(); + + if (clickedOperator == "dtm_1") { + QString text = display->text(); + mem_1->setText(text); + } else if (clickedOperator == "dtm_2"){ + QString text = display->text(); + mem_2->setText(text); + } else if (clickedOperator == "dtm_3"){ + QString text = display->text(); + mem_3->setText(text); + } else if (clickedOperator == "dtm_4"){ + QString text = display->text(); + mem_4->setText(text); + } else if (clickedOperator == "mtd_1"){ + QString text = mem_1->text(); + display->setText(text); + } else if (clickedOperator == "mtd_2"){ + QString text = mem_2->text(); + display->setText(text); + } else if (clickedOperator == "mtd_3"){ + QString text = mem_3->text(); + display->setText(text); + } else if (clickedOperator == "mtd_4"){ + QString text = mem_4->text(); + display->setText(text); + } + +} + + +void MiniCalc::equalClicked() +{ + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.truncate( 0 ); + } + if (!pendingAdditiveOperator.isEmpty()) { + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + pendingAdditiveOperator.truncate(0); + } else { + sumSoFar = operand; + } + + display->setText(QString::number(sumSoFar)); + sumSoFar = 0.0; + waitingForOperand = true; +} + + +bool MiniCalc::calcpercent(double rightOperand, const QString &pendingOperator) +{ + if (pendingOperator == tr("+")) { + sumSoFar = sumSoFar + ((sumSoFar / 100) * rightOperand); + + } else if (pendingOperator == tr("-")) { + sumSoFar = sumSoFar - ((sumSoFar / 100) * rightOperand); + + } else if (pendingOperator == tr("\327")) { + factorSoFar = (factorSoFar /rightOperand ) * 100; + + } else if (pendingOperator == tr("/")) { + if (rightOperand == 0.0) + return false; + factorSoFar = (factorSoFar / 100) * rightOperand; + + } + return true; +} + + +void MiniCalc::percentClicked() +{ + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calcpercent(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.truncate( 0 ); + } + + if (!pendingAdditiveOperator.isEmpty()) { + if (!calcpercent(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + pendingAdditiveOperator.truncate(0); + } else { + sumSoFar = operand; + } + + display->setText(QString::number(sumSoFar)); + sumSoFar = 0.0; + waitingForOperand = true; + +} + diff --git a/src/lib/aminicalc.h b/src/lib/aminicalc.h new file mode 100644 index 0000000..f5c8840 --- /dev/null +++ b/src/lib/aminicalc.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'aminicalc.ui' +** +** Created: 2008-06-18T13:52:59 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#ifndef MINICALC_H +#define MINICALC_H + +#include +#include + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QSpacerItem; +class QFrame; +class QPushButton; +class QLineEdit; +class QLabel; + +class MiniCalc : public QDialog +{ + Q_OBJECT + +public: + MiniCalc( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~MiniCalc(); + + void abortOperation(); + bool calculate(double rightOperand, const QString &pendingOperator); + bool calcpercent(double rightOperand, const QString &pendingOperator); + + double sumInMemory; + double sumSoFar; + double factorSoFar; + QString pendingAdditiveOperator; + QString pendingMultiplicativeOperator; + bool waitingForOperand; + + QFrame* calcFrame; + QPushButton* extMem; + QLineEdit* display; + QPushButton* toDocButton; + QPushButton* clearMemoryButton; + QPushButton* btn_7; + QPushButton* btn_8; + QPushButton* btn_9; + QPushButton* plusButton; + QPushButton* changeSignButton; + QPushButton* clearButton; + QPushButton* readMemoryButton; + QPushButton* btn_4; + QPushButton* btn_5; + QPushButton* btn_6; + QPushButton* minusButton; + QPushButton* persentButton; + QPushButton* clearAllButton; + QPushButton* minusMemoryButton; + QPushButton* btn_1; + QPushButton* btn_2; + QPushButton* btn_3; + QPushButton* timesButton; + QPushButton* reciprocalButton; + QPushButton* backspaceButton; + QPushButton* addToMemoryButton; + QPushButton* btn_0; + QPushButton* doubleZero; + QPushButton* pointButton; + QPushButton* divisionButton; + QPushButton* powButton; + QPushButton* equalButton; + QFrame* extension; + QLabel* label; + QLineEdit* mem_1; + QPushButton* mem_to_disp_4; + QPushButton* disp_to_mem_4; + QPushButton* mem_to_disp_3; + QPushButton* disp_to_mem_3; + QPushButton* disp_to_mem_1; + QLineEdit* mem_4; + QLineEdit* mem_3; + QPushButton* disp_to_mem_2; + QLineEdit* mem_2; + QPushButton* mem_to_disp_2; + QPushButton* mem_to_disp_1; + +public slots: + virtual void digitClicked(); + virtual void unaryOperatorClicked(); + virtual void additiveOperatorClicked(); + virtual void multiplicativeOperatorClicked(); + virtual void equalClicked(); + virtual void dzClicked(); + virtual void pointClicked(); + virtual void percentClicked(); + virtual void changeSignClicked(); + virtual void backspaceClicked(); + virtual void clear(); + virtual void clearAll(); + virtual void clearMemory(); + virtual void readMemory(); + virtual void minusMemory(); + virtual void addToMemory(); + virtual void toDoc(); + virtual void extMemClicked(); + virtual void extMemOperations(); + +protected: + QGridLayout* MiniCalcLayout; + QGridLayout* calcFrameLayout; + QGridLayout* extensionLayout; + +protected slots: + virtual void languageChange(); + +}; + +#endif // MINICALC_H diff --git a/src/plugins/wfield.cpp b/src/plugins/wfield.cpp index 628a93d..bb63c9a 100644 --- a/src/plugins/wfield.cpp +++ b/src/plugins/wfield.cpp @@ -146,13 +146,13 @@ wField::widgetInit() checkBox->hide(); disconnect( checkBox, SIGNAL( valueChanged ( const QString & ) ), this, SLOT( setValue( const QString & ) ) ); - + disconnect( checkBox, SIGNAL( toggled (bool) ), checkBox, SLOT( on_toggled() ) ); // checkBox->disconnect(); layout()->remove(checkBox); //TODO: need rewrite if (!vFieldType.isEmpty()) sscanf((const char *)vFieldType,"%s %i %i", s1, &n1, &n2); - + switch (vEditorType) { case Numberic: @@ -184,12 +184,12 @@ wField::widgetInit() connect( lineEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( setValue( const QString & ) ) ); connect( lineEdit, SIGNAL( lostFocus() ), this, SLOT( focusOutEvent()) ); - + setFocusProxy(lineEdit); layout()->add( lineEdit ); lineEdit->show(); break; - + case String: if(vFieldType.isEmpty()) { @@ -204,12 +204,12 @@ wField::widgetInit() connect( lineEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( setValue( const QString & ) ) ); connect( lineEdit, SIGNAL( lostFocus() ), this, SLOT( focusOutEvent()) ); - + setFocusProxy(lineEdit); layout()->add( lineEdit ); lineEdit->show(); break; - + case Date: case DateTime: // used object wDateTime, inherits QDateTime @@ -231,7 +231,7 @@ wField::widgetInit() objButton->show(); dateEdit->show(); break; - + case Catalogue: md_oid = n1; objLabel->setFrameShape( QFrame::Box ); @@ -242,7 +242,7 @@ wField::widgetInit() objButton->setPixmap( QPixmap::fromMimeSource( "wcatalogue.png" ) ); connect( objButton, SIGNAL( clicked() ), this, SLOT( fieldSelect() ) ); - + setFocusProxy(objButton); layout()->add( objLabel ); layout()->add( objButton ); @@ -268,18 +268,18 @@ wField::widgetInit() objLabel->show(); objButton->show(); break; - + case Boolean: // connect( checkBox, SIGNAL( lostFocus() ), this, SLOT( focusOutEvent()) ); connect( checkBox, SIGNAL( valueChanged ( const QString & ) ), this, SLOT( setValue( const QString & ) ) ); - + connect( checkBox, SIGNAL( toggled (bool) ), checkBox, SLOT( on_toggled() ) ); setFocusProxy(checkBox); layout()->add(checkBox); checkBox->show(); break; - + default: objLabel->setText("UnknownField"); objLabel->setFrameShape(QFrame::Box); @@ -389,7 +389,7 @@ wField::setValue(const QString &newvalue) // conventering date-time to date, and if new value is NULL set up current locale date. // date must be stored in server in format ISO str = newvalue; - if(newvalue.isEmpty()) + if(newvalue.isEmpty()) { str= QDateTime::currentDateTime(Qt::LocalTime).toString(Qt::ISODate); } @@ -404,11 +404,11 @@ wField::setValue(const QString &newvalue) break; case Boolean: vValue = newvalue; - if(newvalue == "1") + if(newvalue == "1") { checkBox->setChecked(true); } - else + else { checkBox->setChecked(false); } @@ -481,7 +481,7 @@ wField::fieldSelect() switch (vEditorType) { case Catalogue: - if ( engine ) + if ( engine ) { int fid = md->getDefaultFormId( md->find( md_oid ), md_action_view); if ( !fid ) @@ -490,13 +490,13 @@ wField::fieldSelect() return; } f = engine->openForm( md_oid, 0, md_action_view, 0, false ); - if ( f ) + if ( f ) { connect(f, SIGNAL(selected( Q_ULLONG )), this, SLOT(on_selected( Q_ULLONG ))); f->closeAfterSelect = true; } } - else + else { aLog::print(aLog::MT_ERROR, tr("wField::fieldSelect no engine")); } @@ -520,7 +520,7 @@ wField::fieldSelect() connect(f, SIGNAL(selected( Q_ULLONG )), this, SLOT(on_selected( Q_ULLONG ))); f->closeAfterSelect = true; } - + } else { @@ -601,12 +601,16 @@ wField::SetReadOnly(bool fl) { switch (vEditorType) { case Numberic: + lineEdit->setReadOnly(fl); + objButton->setDisabled( fl ); + break; case String: lineEdit->setReadOnly(fl); break; case Date: case DateTime: dateEdit->setDisabled(fl); + objButton->setDisabled( fl ); break; case Catalogue: objButton->setDisabled( fl ); @@ -614,7 +618,7 @@ wField::SetReadOnly(bool fl) case Document: objButton->setDisabled( fl ); break; - case Boolean: + case Boolean: checkBox->setDisabled( fl ); break; default: @@ -690,7 +694,7 @@ wCheckBox::on_toggled() /** - * \ru + * \ru * \brief Задает значение полю dateEdit запросив его у пользователя. * \_ru */ @@ -703,203 +707,3 @@ wField::popupCalendar() dateEdit->setDate(date); dateEdit->setFocus(); } - -/** - * \ru - * \brief Запрашивает дату у пользователя, показав ему календарик. - * \return дату, указанную пользователем. - * \_ru - */ -QDate -PopupCalendar::getDate(QWidget *parent, const QDate &day, QPoint pos) -{ - PopupCalendar *calendar = new PopupCalendar(day, pos, parent); - calendar->exec(); - QDate date = calendar->day(); - delete calendar; - return date; -} - - -/** - * \ru - * \brief Осуществляет отрисовку календарика, обрабатывая событие PaintEvent виджета PopupCalendar. - * \_ru - */ -void -PopupCalendar::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - painter.setClipRegion(event->region()); - painter.setFont(smallFont); - int w = width();// Ширина окна - int h = height(); // Высота окна - int dayw = w / COLS; // Ширина ячейки - int dayh = h / (ROWS + 2); // Высота ячейки - - QRect rect; - QColor color = colorGroup().light(); - QColor f_color = "red"; - QColor g_color = "green"; - QColor b_color = "blue"; - // Формируем строку с годом и месяцем - painter.fillRect(1, 1, dayw - 2, dayh - 1, color); - painter.drawText(1, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString("<< "), -1, &rect); - painter.fillRect(dayw, 1, dayw - 2, dayh - 1, color); - painter.drawText(dayw, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" < "), -1, &rect); - painter.drawText(dayw*2+1, 1, dayw*3- 1, dayh - 1, AlignHCenter, today.toString("MMM, yyyy"), -1, &rect); - painter.fillRect(w-(dayw*2), 1, dayw - 2, dayh - 1, color); - painter.drawText(w-(dayw*2), 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" > "), -1, &rect); - painter.fillRect(w-dayw, 1, dayw - 2, dayh - 1, color); - painter.drawText(w-dayw, 1, dayw - 1, dayh - 1, AlignHCenter, today.toString(" >>"), -1, &rect); - -// Формируем строку с днями недели - int i; - int y = dayh; - for (i = 0; i < 7; i++) { - - painter.drawText(dayw * i + 1, y, dayw, dayh - 1, - AlignHCenter, QDate::shortDayName(i+1), -1, &rect); - } - - // Заплняем таблицу календаря - QDate day(today.year(), today.month(), 1); - int day_pos = day.dayOfWeek()-1; - day = day.addDays(-day_pos); - y += dayh; - for (int j = 0; j < ROWS-1; ++j) - for (i = 0; i < COLS; ++i) { - color = (day == today) ? colorGroup().light() : ( ( i < 5 ) ? colorGroup().light() : colorGroup().midlight()); - if (day == today){ - painter.fillRect(dayw * i + 1, dayh * j + y + 1, dayw - 1, dayh - 1, b_color); - painter.fillRect(dayw * i + 3, dayh * j + y + 3, dayw - 5, dayh - 5, color); - }else{ - painter.fillRect(dayw * i + 1, dayh * j + y + 1, dayw - 1, dayh - 1, color); - } - (today.month() != day.month() )? painter.setPen(colorGroup().mid()): ( ( i < 5 ) ? painter.setPen(colorGroup().foreground()):painter.setPen(f_color)); - painter.drawText(dayw * i + 2, dayh * j + y + 2, dayw, dayh, AlignTop|AlignHCenter, day.toString("d")); - day = day.addDays(1); - } - // Формируем последнюю строку - painter.fillRect(1, h - dayh - 1, dayw*2, dayh - 1, b_color); - painter.fillRect(3, h - dayh + 1, dayw*2-4, dayh - 5, color); - painter.setPen(colorGroup().foreground()); - painter.drawText(2, h - dayh, dayw*2-2, dayh - 3, AlignTop|AlignHCenter, "Now"); - painter.drawText(w - dayw*3, h - dayh, dayw*3-2, dayh - 1, AlignTop|AlignHCenter, QString(tr("Week: %1").arg(today.weekNumber()))); -} - -/** - * \ru - * \brief Обрабатывает пользовательские действия по выбору даты в календарике. - * - * Записывает значение выбранной пользователем даты в свойство виджета. - * - * \_ru - */ -void -PopupCalendar::keyPressEvent(QKeyEvent *event) -{ - int days = 0; - switch (event->key()) { - case Key_Left: days = -1; break; - case Key_Right: days = 1; break; - case Key_Up: days = -COLS; break; - case Key_Down: days = COLS; break; - case Key_PageUp: days = today.daysTo(today.addMonths(-1)); break; - case Key_PageDown: days = today.daysTo(today.addMonths(1)); break; - case Key_Home: days = today.daysTo(today.addYears(-1)); break; - case Key_End: days = today.daysTo(today.addYears(1)); break; - case Key_Escape: today = original; accept(); break; - case Key_Space: // fallthrough - case Key_Enter: // fallthrough - case Key_Return: accept(); return; - default: QDialog::keyPressEvent(event); return; - } - - QDate day = today.addDays(days); - if (day != today) - setDay(day); -} - -/** - * \ru - * \brief Обрабатывает пользовательские действия мышкой по выбору даты в календарике. - * - * Записывает значение выбранной пользователем даты в свойство виджета. - * - * \_ru - */ -void -PopupCalendar::mousePressEvent(QMouseEvent *event) -{ - QDate day = today; - int w = width(); - int h = height(); - int dayh2 = (h / (ROWS + 2)) * 2; - int dayh = h / (ROWS + 2); // Высота строки - int dayw = w / COLS; // Ширина колонки - if (event->y() < dayh) { - if (event->x() > 1 && event->x() < dayw) day = day.addYears(-1); - if (event->x() > dayw && event->x() < dayw*2 ) day = day.addMonths(-1); - if (event->x() > (w - dayw*2) && event->x() < (w - dayw) ) day = day.addMonths(1); - if (event->x() > (w - dayw) ) day = day.addYears(1); - } else { - if (event->y() > dayh2 && event->y() < h - dayh) { - int xday = event->x() / (width() / (COLS) ); - int yday = (event->y() - dayh2) / ((h - dayh2) / ROWS); - day = QDate(today.year(), today.month(), 1); - int day_pos = day.dayOfWeek()-1; - day = day.addDays(xday + (COLS * yday) - (day_pos)); - }else{ - if (event->x() > 1 && event->x() < dayw*2) { - day = today.currentDate(); - } - } - } - if (day != today) setDay(day); -} - -QSize -PopupCalendar::sizeHint() const -{ - QFontMetrics fm(smallFont); - return QSize(COLS * (fm.width(tr("Wed"))+2), (ROWS + 2) * fm.height() * 1.2); -} - -/** - * \ru - * \brief Сеттер задающий дату виджету. - * - * Вызывает перерисовку виджета. - * - * \_ru - */ -void -PopupCalendar::setDay(const QDate &day) -{ - today = day; - update(); -} - - -/** - * \ru - * \brief Конструктор. Инициализирует свойства виджета, задает надпись в шапке виджета. - * - * \_ru - */ -PopupCalendar::PopupCalendar(const QDate &day, QPoint pos, - QWidget *parent, const char *name) - : QDialog(parent, name), today(day), original(day) -{ - setCaption(tr("A-Calendar")); - if (!pos.isNull()) move(pos); - smallFont = font(); - if (smallFont.pointSize() >= 10) { - smallFont.setPointSize(smallFont.pointSize() - 2); - smallFont.setBold(true); - } - - setFixedSize(sizeHint()); - setFocusPolicy(StrongFocus); -} -- 1.7.1