EventView::EventView(FileSet * _fileSet, unsigned int _history, char const * _name) :
  Super(NULL, _name),
  fileSet_(_fileSet),
  list_(NULL),
  last_(NULL),
  internalSetSelection_(false),
  history_(_history)
{
  setCaption("Event View");

  QVBoxLayout * topBox = new QVBoxLayout(this, 0, -1, "boxLayout");

  QVGroupBox * eventBox = new QVGroupBox(this, "eventBox");
  list_ = new QListView(eventBox, "list");

  list_->addColumn("Time Stamp");
  list_->addColumn("Domain Name");
  list_->addColumn("Type Name");
  list_->addColumn("Event Name");
  list_->setSorting(-1);
  list_->setAllColumnsShowFocus(true);

  topBox->addSpacing(10);
  topBox->addWidget(eventBox);
  eventBox->setTitle("Events");

  // connect to file set events
  FileSet::FileVector::iterator first, last = fileSet_->fileVector().end();
  for (first = fileSet_->fileVector().begin(); first != last; ++first) {
    connect(*first, SIGNAL(newEvent(const QString&,const QString&,const QString&,const QString&)), 
	    this, SLOT(insertEvent(const QString&,const QString&,const QString&,const QString&)));
  }

  connect(list_, SIGNAL(selectionChanged(QListViewItem *)),
	  this, SLOT(selectionChanged(QListViewItem *)));

  fileSet_->getEvents(fileSet_->coursorTime(), history_);

  show();
}
TesterReport::TesterReport (QWidget *p) : QWidget (p)
{
  QVBoxLayout *vbox = new QVBoxLayout(this);
  vbox->setMargin(5);
  vbox->setSpacing(5);

  tradeList = new QTable(0, 9, this);
  tradeList->setSelectionMode(QTable::Single);
  tradeList->setSorting(FALSE);
  QHeader *header = tradeList->horizontalHeader();
  header->setLabel(0, tr("Type"), 40);
  header->setLabel(1, tr("Entry"), 90);
  header->setLabel(2, tr("Entry Price"), 60);
  header->setLabel(3, tr("Exit"), 90);
  header->setLabel(4, tr("Exit Price"), 60);
  header->setLabel(5, tr("Signal"), -1);
  header->setLabel(6, tr("Profit"), 60);
  header->setLabel(7, tr("Account"), -1);
  header->setLabel(8, tr("Vol"), 60);
  vbox->addWidget(tradeList);

  int loop;
  for (loop = 0; loop < 9; loop++)
    tradeList->setColumnReadOnly(loop, TRUE);
    
  // test summary
  
  QHBoxLayout *hbox = new QHBoxLayout(vbox);
  hbox->setSpacing(5);

  QVGroupBox *gbox = new QVGroupBox(tr("Test Summary"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  QLabel *label = new QLabel(tr("Account Balance "), gbox);
  summaryBalance = new QLabel(" ", gbox);
  
  label = new QLabel(tr("Net Profit "), gbox);
  summaryNetProfit = new QLabel(" ", gbox);

  label = new QLabel(tr("Net Profit % "), gbox);
  summaryNetPercentage = new QLabel(" ", gbox);

  label = new QLabel(tr("Initial Investment "), gbox);
  summaryInvestment = new QLabel(" ", gbox);

  label = new QLabel(tr("Commissions "), gbox);
  summaryCommission = new QLabel(" ", gbox);

  label = new QLabel(tr("Largest Drawdown "), gbox);
  summaryDrawdown = new QLabel(" ", gbox);

  label = new QLabel(tr("Trades "), gbox);
  summaryTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Long Trades "), gbox);
  summaryLongTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Short Trades "), gbox);
  summaryShortTrades = new QLabel(" ", gbox);
  
  // win summary

  gbox = new QVGroupBox(tr("Win Summary"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  label = new QLabel(tr("Trades "), gbox);
  summaryWinTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Profit "), gbox);
  summaryTotalWinTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Average "), gbox);
  summaryAverageWin = new QLabel(" ", gbox);

  label = new QLabel(tr("Largest "), gbox);
  summaryLargestWin = new QLabel(" ", gbox);

  label = new QLabel(tr("Long Trades "), gbox);
  summaryWinLongTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Short Trades "), gbox);
  summaryWinShortTrades = new QLabel(" ", gbox);

  // lose summary

  gbox = new QVGroupBox(tr("Loss Summary"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  label = new QLabel(tr("Trades "), gbox);
  summaryLoseTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Profit "), gbox);
  summaryTotalLoseTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Average "), gbox);
  summaryAverageLose = new QLabel(" ", gbox);

  label = new QLabel(tr("Largest "), gbox);
  summaryLargestLose = new QLabel(" ", gbox);

  label = new QLabel(tr("Long Trades "), gbox);
  summaryLoseLongTrades = new QLabel(" ", gbox);

  label = new QLabel(tr("Short Trades "), gbox);
  summaryLoseShortTrades = new QLabel(" ", gbox);
}
KTreemapPage::KTreemapPage( KSettingsDialog *	dialog,
					    QWidget *		parent,
					    KDirStatApp *	mainWin )
    : KSettingsPage( dialog, parent )
    , _mainWin( mainWin )
{
    // kdDebug() << k_funcinfo << endl;

    QVBoxLayout * layout = new QVBoxLayout( this, 0, 0 ); // parent, border, spacing

    QVBox * vbox	= new QVBox( this );
    vbox->setSpacing( dialog->spacingHint() );
    layout->addWidget( vbox );

    _squarify		= new QCheckBox( i18n( "S&quarify Treemap"	), vbox );
    _doCushionShading	= new QCheckBox( i18n( "Use C&ushion Shading"	), vbox );


    // Cushion parameters

    QVGroupBox * gbox	= new QVGroupBox( i18n( "Cushion Parameters" ), vbox );
    _cushionParams	= gbox;
    gbox->addSpace( 7 );
    gbox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );

    QLabel * label	= new QLabel( i18n( "Ambient &Light" ), gbox );
    QHBox * hbox	= new QHBox( gbox );
    _ambientLight	= new QSlider ( MinAmbientLight, MaxAmbientLight, 10,	// min, max, pageStep
					DefaultAmbientLight, Horizontal, hbox );
    _ambientLightSB	= new QSpinBox( MinAmbientLight, MaxAmbientLight, 1,	// min, max, step
					hbox );
    _ambientLightSB->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
    label->setBuddy( _ambientLightSB );

    gbox->addSpace( 7 );
    label		= new QLabel( i18n( "&Height Scale" ), gbox );
    hbox		= new QHBox( gbox );
    _heightScalePercent = new QSlider( MinHeightScalePercent, MaxHeightScalePercent, 10,   // min, max, pageStep
				       DefaultHeightScalePercent, Horizontal, hbox );
    _heightScalePercentSB = new QSpinBox( MinHeightScalePercent, MaxHeightScalePercent, 1, // min, max, step
					  hbox );
    _heightScalePercentSB->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
    label->setBuddy( _heightScalePercentSB );

    gbox->addSpace( 10 );
    _ensureContrast	= new QCheckBox( i18n( "Draw Lines if Lo&w Contrast"	), gbox );


    hbox		= new QHBox( gbox );
    _forceCushionGrid	= new QCheckBox( i18n( "Always Draw &Grid"		), hbox );
    addHStretch( hbox );

    _cushionGridColorL	= new QLabel( "	   " + i18n( "Gr&id Color: " ), hbox );
    _cushionGridColor	= new KColorButton( hbox );
    _cushionGridColorL->setBuddy( _cushionGridColor );
    _cushionGridColorL->setAlignment( AlignRight | AlignVCenter );

    // addVStretch( vbox );


    // Plain treemaps parameters

    _plainTileParams	= new QHGroupBox( i18n( "Colors for Plain Treemaps" ), vbox );

    _plainTileParams->addSpace( 7 );
    label		= new QLabel( i18n( "&Files: " ), _plainTileParams );
    _fileFillColor	= new KColorButton( _plainTileParams );
    label->setBuddy( _fileFillColor );
    label->setAlignment( AlignRight | AlignVCenter );

    label		= new QLabel( "	   " + i18n( "&Directories: " ), _plainTileParams );
    _dirFillColor	= new KColorButton( _plainTileParams );
    label->setBuddy( _dirFillColor );
    label->setAlignment( AlignRight | AlignVCenter );

    label		= new QLabel( i18n( "Gr&id: " ), _plainTileParams );
    _outlineColor	= new KColorButton( _plainTileParams );
    label->setBuddy( _outlineColor );
    label->setAlignment( AlignRight | AlignVCenter );


    // Misc

    QWidget * gridBox	= new QWidget( vbox );
    QGridLayout * grid	= new QGridLayout( gridBox, 2, 3, dialog->spacingHint() ); // rows, cols, spacing
    grid->setColStretch( 0, 0 ); // (col, stretch) don't stretch this column
    grid->setColStretch( 1, 0 ); // don't stretch
    grid->setColStretch( 2, 1 ); // stretch this as you like

    label		= new QLabel( i18n( "Hi&ghlight R&ectangle: " ), gridBox );
    _highlightColor	= new KColorButton( gridBox );
    label->setBuddy( _highlightColor );

    grid->addWidget( label,		0, 0 );
    grid->addWidget( _highlightColor,	0, 1 );


    label		= new QLabel( i18n( "Minim&um Treemap Tile Size: " ), gridBox );
    _minTileSize	= new QSpinBox( 0, 30, 1, gridBox ); // min, max, step, parent
    label->setBuddy( _minTileSize );

    grid->addWidget( label,		1, 0 );
    grid->addWidget( _minTileSize,	1, 1 );

    _autoResize		= new QCheckBox( i18n( "Auto-&Resize Treemap" ), vbox );



    // Connections

    connect( _ambientLight,		SIGNAL( valueChanged(int) ),
	     _ambientLightSB,		SLOT  ( setValue    (int) ) );

    connect( _ambientLightSB,		SIGNAL( valueChanged(int) ),
	     _ambientLight,		SLOT  ( setValue    (int) ) );


    connect( _heightScalePercent,	SIGNAL( valueChanged(int) ),
	     _heightScalePercentSB,	SLOT  ( setValue    (int) ) );

    connect( _heightScalePercentSB,	SIGNAL( valueChanged(int) ),
	     _heightScalePercent,	SLOT  ( setValue    (int) ) );


    connect( _doCushionShading, SIGNAL( stateChanged( int ) ), this, SLOT( checkEnabledState() ) );
    connect( _forceCushionGrid, SIGNAL( stateChanged( int ) ), this, SLOT( checkEnabledState() ) );

    checkEnabledState();
}
/////////////////////////////////////////
/////////////////////////////////////////
///  dlg
/////////////////////////////////////////
/////////////////////////////////////////
KMPopFilterCnfrmDlg::KMPopFilterCnfrmDlg(QPtrList<KMPopHeaders> *aHeaders, const QString &aAccount, bool aShowLaterMsgs, QWidget *aParent,
        const char *aName)
    : KDialogBase(aParent, aName, true, i18n("POP Filter"), Ok | Help, Ok, false)
{
    unsigned int rulesetCount = 0;
    //mHeaders = aHeaders;
    mShowLaterMsgs = aShowLaterMsgs;
    mLowerBoxVisible = false;

    QWidget *w = new QWidget(this);
    setMainWidget(w);

    QVBoxLayout *vbl = new QVBoxLayout(w, 0, spacingHint());

    QLabel *l = new QLabel(i18n("Messages to filter found on POP Account: <b>%1</b><p>"
                                "The messages shown exceed the maximum size limit you defined for this account.<br>You can select "
                                "what you want to do with them by checking the appropriate button.").arg(aAccount), w);
    vbl->addWidget(l);

    QVGroupBox *upperBox = new QVGroupBox(i18n("Messages Exceeding Size"), w);
    upperBox->hide();
    KMPopHeadersView *lv = new KMPopHeadersView(upperBox, this);
    vbl->addWidget(upperBox);

    QVGroupBox *lowerBox = new QVGroupBox(i18n("Ruleset Filtered Messages: none"), w);
    QString checkBoxText((aShowLaterMsgs) ?
                         i18n("Show messages matched by a ruleset and tagged 'Download' or 'Delete'") :
                         i18n("Show messages matched by a filter ruleset"));
    QCheckBox *cb = new QCheckBox(checkBoxText, lowerBox);
    cb->setEnabled(false);
    mFilteredHeaders = new KMPopHeadersView(lowerBox, this);
    mFilteredHeaders->hide();
    vbl->addWidget(lowerBox);

    mFilteredHeaders->header()->setResizeEnabled(false, 8);
    mFilteredHeaders->setColumnWidth(8, 0);

    // fill the listviews with data from the headers
    KMPopHeaders *headers;
    for(headers = aHeaders->first(); headers; headers = aHeaders->next())
    {
        KMPopHeadersViewItem *lvi = 0;

        if(headers->ruleMatched())
        {
            if(aShowLaterMsgs && headers->action() == Later)
            {
                // insert messages tagged 'later' only
                lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
                mFilteredHeaders->show();
                mLowerBoxVisible = true;
            }
            else if(aShowLaterMsgs)
            {
                // enable checkbox to show 'delete' and 'download' msgs
                // but don't insert them into the listview yet
                mDDLList.append(headers);
                cb->setEnabled(true);
            }
            else if(!aShowLaterMsgs)
            {
                // insert all messaged tagged by a ruleset, enable
                // the checkbox, but don't show the listview yet
                lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
                cb->setEnabled(true);
            }
            rulesetCount++;
        }
        else
        {
            // insert all messages not tagged by a ruleset
            // into the upper listview
            lvi = new KMPopHeadersViewItem(lv, headers->action());
            upperBox->show();
        }

        if(lvi)
        {
            mItemMap[lvi] = headers;
            setupLVI(lvi, headers->header());
        }
    }

    if(rulesetCount)
        lowerBox->setTitle(i18n("Ruleset Filtered Messages: %1").arg(rulesetCount));

    // connect signals and slots
    connect(lv, SIGNAL(pressed(QListViewItem *, const QPoint &, int)),
            this, SLOT(slotPressed(QListViewItem *, const QPoint &, int)));
    connect(mFilteredHeaders, SIGNAL(pressed(QListViewItem *, const QPoint &, int)),
            this, SLOT(slotPressed(QListViewItem *, const QPoint &, int)));
    connect(cb, SIGNAL(toggled(bool)),
            this, SLOT(slotToggled(bool)));

    adjustSize();
    QTimer::singleShot(0, this, SLOT(slotUpdateMinimumSize()));
}
TesterStopPage::TesterStopPage (QWidget *p) : QWidget (p)
{
  customShortStopLine = 0;
  customLongStopLine = 0;

  QVBoxLayout *vbox = new QVBoxLayout(this);
  vbox->setMargin(5);
  vbox->setSpacing(10);
  
  QHBoxLayout *hbox = new QHBoxLayout(vbox);
  hbox->setSpacing(5);

  QVGroupBox *gbox = new QVGroupBox(tr("Maximum Loss"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  maximumLossCheck = new QCheckBox(tr("Enabled"), gbox);
  connect(maximumLossCheck, SIGNAL(toggled(bool)), this, SLOT(maximumLossToggled(bool)));
  gbox->addSpace(0);

  maximumLossLong = new QCheckBox(tr("Long"), gbox);
  gbox->addSpace(0);

  maximumLossShort = new QCheckBox(tr("Short"), gbox);
  gbox->addSpace(0);

  validator = new QDoubleValidator(0, 999999, 2, this);

  QLabel *label = new QLabel(tr("Loss %"), gbox);

  maximumLossEdit = new QLineEdit("0", gbox);
  maximumLossEdit->setValidator(validator);

  gbox = new QVGroupBox(tr("Profit"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  profitCheck = new QCheckBox(tr("Enabled"), gbox);
  connect(profitCheck, SIGNAL(toggled(bool)), this, SLOT(profitToggled(bool)));
  gbox->addSpace(0);

  profitLong = new QCheckBox(tr("Long"), gbox);
  gbox->addSpace(0);

  profitShort = new QCheckBox(tr("Short"), gbox);
  gbox->addSpace(0);

  label = new QLabel(tr("Profit %"), gbox);

  profitEdit = new QLineEdit("0", gbox);
  profitEdit->setValidator(validator);

  gbox = new QVGroupBox(tr("Trailing"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(2);
  hbox->addWidget(gbox);

  trailingCheck = new QCheckBox(tr("Enabled"), gbox);
  connect(trailingCheck, SIGNAL(toggled(bool)), this, SLOT(trailingToggled(bool)));
  gbox->addSpace(0);

  trailingLong = new QCheckBox(tr("Long"), gbox);
  gbox->addSpace(0);

  trailingShort = new QCheckBox(tr("Short"), gbox);
  gbox->addSpace(0);

  label = new QLabel(tr("Loss %"), gbox);

  trailingEdit = new QLineEdit("0", gbox);
  trailingEdit->setValidator(validator);
  
  QGridLayout *grid = new QGridLayout(vbox, 1, 2);
  grid->setSpacing(5);
  
  gbox = new QVGroupBox(tr("Custom Long Stop"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(1);
  grid->addWidget(gbox, 0, 0);
  
  customLongStopCheck = new QCheckBox(tr("Enabled"), gbox);
  connect(customLongStopCheck, SIGNAL(toggled(bool)), this, SLOT(customLongStopToggled(bool)));

  customLongStopEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  

  gbox = new QVGroupBox(tr("Custom Short Stop"), this);
  gbox->setInsideSpacing(2);
  gbox->setColumns(1);
  grid->addWidget(gbox, 0, 1);
  
  customShortStopCheck = new QCheckBox(tr("Enabled"), gbox);
  connect(customShortStopCheck, SIGNAL(toggled(bool)), this, SLOT(customShortStopToggled(bool)));

  customShortStopEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  
  
  maximumLossToggled(FALSE);
  profitToggled(FALSE);
  trailingToggled(FALSE);
  customLongStopToggled(FALSE);
  customShortStopToggled(FALSE);
}
DigiSettingsDialog::DigiSettingsDialog(TextDoc *Doc_)
                  : QDialog(Doc_, 0, true, Qt::WDestructiveClose)
{
  Doc = Doc_;
  setCaption(tr("Document Settings"));

  Expr.setPattern("[0-9][0-9a-zA-Z ]+"); // valid expression for LineEdit
  Validator = new QRegExpValidator(Expr, this);

  QVBoxLayout *all = new QVBoxLayout(this);
  all->setMargin(5);

  QVGroupBox *setGroup = new QVGroupBox(tr("Digital Simulation Settings"), this);
  all->addWidget(setGroup);

  QButtonGroup *toggleGroup = new QButtonGroup();
  simRadio = new QRadioButton(tr("Simulation"), setGroup);
  simRadio->setChecked(Doc->simulation);

  QHBox *hb1 = new QHBox(setGroup);
  hb1->setSpacing(5);
  TimeLabel = new QLabel(tr("Duration of Simulation:"), hb1);
  Doc->loadSimulationTime(SimTime);
  TimeEdit = new QLineEdit(hb1);
  TimeEdit->setValidator(Validator);
  TimeEdit->setText(SimTime);

  QRadioButton *comRadio = new QRadioButton(tr("Precompile Module"), setGroup);
  toggleGroup->insert(simRadio);
  toggleGroup->insert(comRadio);
  connect(toggleGroup, SIGNAL(clicked(int)), SLOT(slotChangeMode(int)));

  QHBox *hb3 = new QHBox(setGroup);
  hb3->setSpacing(5);
  NameLabel = new QLabel(tr("Library Name:"), hb3);
  NameEdit = new QLineEdit(hb3);
  NameEdit->setText(Doc->Library);

  setGroup->addSpace(15);
  QHBox *hb2 = new QHBox(setGroup);
  hb2->setSpacing(5);
  LibLabel = new QLabel(tr("Libraries:"), hb2);
  LibEdit = new QLineEdit(hb2);
  LibEdit->setText(Doc->Libraries);

  all->addSpacing(5);
  all->addStretch();
  QHBox *Buttons = new QHBox(this);
  all->addWidget(Buttons);
  QPushButton *ButtonOk = new QPushButton(tr("Ok"), Buttons);
  QPushButton *ButtonCancel = new QPushButton(tr("Cancel"), Buttons);
  connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
  connect(ButtonCancel, SIGNAL(clicked()), SLOT(reject()));

  simRadio->setChecked(Doc->simulation);
  Doc->SimOpenDpl = Doc->simulation ? true : false;
  comRadio->setChecked(!Doc->simulation);
  slotChangeMode(!Doc->simulation);

  ButtonOk->setDefault(true);
  if(Doc->simulation) {
    setFocusProxy(TimeEdit);
    TimeEdit->setFocus();
  }
  else {
    setFocusProxy(NameEdit);
    NameEdit->setFocus();
  }
}