Esempio n. 1
0
void ColorChooser::loadHistograms(const QImage* imageOriginal)
{
  qApp->processEvents(); // process events just once to fill gray box left over from dropped down menu

  int discretizeMethods = 5;
  int runTime = imageOriginal->width() * discretizeMethods;
  QProgressDialog* dlg = new QProgressDialog(QString(tr("Loading histograms")), "Cancel", 0,
    runTime, m_parent);
  CHECK_PTR_ENGAUGE(dlg);
  dlg->setCaption(tr("Progress"));
  dlg->show();

  loadForegroundPixmap(m_rgbBg);

  intensityHistogram.setAutoDelete(true);
  foregroundHistogram.setAutoDelete(true);
  hueHistogram.setAutoDelete(true);
  saturationHistogram.setAutoDelete(true);
  valueHistogram.setAutoDelete(true);

  loadHistogram(imageOriginal, DiscretizeIntensity, DiscretizeIntensityMax, &intensityHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeForeground, DiscretizeForegroundMax, &foregroundHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeHue, DiscretizeHueMax, &hueHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeSaturation, DiscretizeSaturationMax, &saturationHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeValue, DiscretizeValueMax, &valueHistogram, m_rgbBg, dlg);

  showCurrentHistogram();
  
  chooserCanvas->update();

  ASSERT_ENGAUGE(dlg != 0);
  delete dlg;

  qApp->processEvents(); // process events just once to fill gray box left over from previous window
}
Esempio n. 2
0
/**
 * Saves the selected pictures.
 * First pops up a dialog box asking for the target dir. Then pops up 
 * a progress dialog for feedback.
 */
void MainWindow::saveSelected() 
{
    /* Select target */
    selectWorkDir();

    /* Create a progress dialog */
    QProgressDialog* progress = new QProgressDialog(
        i18n("Downloading ..."), i18n("Cancel"), 100, this, "progress", TRUE);
    progress->setCaption("Download");
    connect(GPMessenger::instance(),SIGNAL(progressChanged(int)),
            progress,SLOT(setProgress(int)));
    progress->setAutoReset(false);
    progress->setAutoClose(false); 
    progress->setProgress(0);
    KApplication::kApplication()->processEvents();
     
    /* Download all pictures */
    for (QIconViewItem *i = iconView->firstItem(); 
                    i && !progress->wasCancelled(); i = i->nextItem() ) {
        if (i->isSelected()) {
            /* Update progress dialog */
            progress->setLabelText(i18n("Downloading ") + i->text() + "...");

            /* Download picture */
            GPInterface::downloadPicture(i->text(),"/");
        }
    } 

    progress->setProgress(100);
    delete progress;
}
Esempio n. 3
0
void FLUtil::createProgressDialog( const QString & l, int tS, const QString & id ) {
  QProgressDialog * pd = dictProgressD_.find( id );
  if ( !pd ) {
    pd = new QProgressDialog( l, 0, tS, 0, 0, true );
    dictProgressD_.insert( id, pd );
    pd->setCaption( "AbanQ" );
  }
}
Esempio n. 4
0
void Segments::makeSegments(QImage &imageProcessed, SegmentSettings seg)
{
    segments.clear(); // autoDelete is on

    // statistics that show up in debug spew
    int madeLines = 0;
    int shortLines = 0; // lines rejected since their segments are too short
    int foldedLines = 0; // lines rejected since they could be into other lines

    // debugging with modal progress dialog box is problematic so make switchable
    const bool useDlg = true;

    // for each new column of pixels, loop through the runs. a run is defined as
    // one or more colored pixels that are all touching, with one uncolored pixel or the
    // image boundary at each end of the set. for each set in the current column, count
    // the number of runs it touches in the adjacent (left and right) columns. here is
    // the pseudocode:
    //   if ((L > 1) || (R > 1))
    //     "this run is at a branch point so ignore the set"
    //   else
    //     if (L == 0)
    //       "this run is the start of a new segment"
    //     else
    //       "this run is appended to the segment on the left
    int width = imageProcessed.width();
    int height = imageProcessed.height();

    QProgressDialog* dlg;
    if (useDlg)
    {

        dlg = new QProgressDialog("Scanning segments in image", "Cancel", 0, width);
        CHECK_PTR_ENGAUGE(dlg);
        dlg->setCaption(QString("Progress"));
        dlg->show();
    }

    bool* lastBool = new bool [height];
    CHECK_PTR_ENGAUGE(lastBool);
    bool* currBool = new bool [height];
    CHECK_PTR_ENGAUGE(currBool);
    bool* nextBool = new bool [height];
    CHECK_PTR_ENGAUGE(nextBool);
    Segment** lastSegment = new Segment* [height];
    CHECK_PTR_ENGAUGE(lastSegment);
    Segment** currSegment = new Segment* [height];
    CHECK_PTR_ENGAUGE(currSegment);

    Discretize discretize;
    loadBool(&discretize, lastBool, &imageProcessed, -1);
    loadBool(&discretize, currBool, &imageProcessed, 0);
    loadBool(&discretize, nextBool, &imageProcessed, 1);
    loadSegment(lastSegment, height);

    for (int x = 0; x < width; x++)
    {
        if (useDlg)
        {
            // update progress bar
            dlg->setValue(x);
            qApp->processEvents();

            if (dlg->wasCanceled())
                // quit scanning. only existing segments will be available
                break;
        }

        matchRunsToSegments(x, height, lastBool, lastSegment, currBool, currSegment, nextBool, seg,
                            &madeLines, &foldedLines, &shortLines);

        // get ready for next column
        scrollBool(lastBool, currBool, height);
        scrollBool(currBool, nextBool, height);
        if (x + 1 < width)
            loadBool(&discretize, nextBool, &imageProcessed, x + 1);
        scrollSegment(lastSegment, currSegment, height);
    }

    if (useDlg)
    {
        dlg->setValue(width);
        delete dlg;
    }

    DigitDebug::scanning(QString("segment lines created ") + QString::number(madeLines) +
                         QString(", too short so removed ") + QString::number(shortLines) +
                         QString(", folded together ") + QString::number(foldedLines));

    delete[] lastBool;
    delete[] currBool;
    delete[] nextBool;
    delete[] lastSegment;
    delete[] currSegment;
}
Esempio n. 5
0
void
PromoBatchMaster::slotPrint()
{
    if (!saveItem(true)) return;
    dataToWidget();

    // Setup grid for printing
    Grid* grid = new Grid(6);
    Grid* header = new Grid(1, grid);
    TextFrame* text;
    text = new TextFrame(tr("Promotion Batch"), header);
    text->setJustify(ALIGN_CENTER);
    text->setFont(Font("Times", 24, 75));
    header->set(USE_NEXT, 0, text);
    if (_curr.executedOn().isNull()) {
        text = new TextFrame(tr("Preliminary"), header);
    } else {
        QString dateText = DateValcon().format(_curr.executedOn());
        text = new TextFrame(tr("Executed On: %1").arg(dateText), header);
    }
    text->setJustify(ALIGN_CENTER);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    header->setColumnWeight(0, 1);

    grid->set(0, 0, 1, grid->columns(), header, Grid::AllSides);
    grid->set(USE_NEXT, 0, "");
    for (int column = 0; column < 6; ++column) {
        grid->setColumnSticky(column, column < 3 ? Grid::Left : Grid::Right);
        grid->setColumnPad(column, 5);
    }
    grid->set(2, 0, tr("Item Number"));
    grid->set(3, 0, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 1, tr("Description"));
    grid->set(3, 1, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 2, tr("Size"));
    grid->set(3, 2, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 3, tr("Current Price"));
    grid->set(3, 3, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 4, tr("Promo Price"));
    grid->set(3, 4, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 5, tr("Ordered"));
    grid->set(3, 5, new LineFrame(grid), Grid::LeftRight);
    grid->setHeaderRows(grid->rows());

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Printing promos..."),
            tr("Cancel"),
            _curr.items().size(),
            this, "Progress", true);
    progress->setMinimumDuration(1000);
    progress->setCaption(tr("Progress"));

    // Print promos
    for (unsigned int i = 0; i < _curr.items().size(); ++i) {
        progress->setProgress(i);
        qApp->processEvents();
        if (progress->wasCancelled()) break;

        Id item_id = _curr.items()[i].item_id;
        if (item_id == INVALID_ID) continue;

        QString number = _curr.items()[i].number;
        QString size = _curr.items()[i].size;
        Price promoPrice = _curr.items()[i].price;
        fixed ordered = _curr.items()[i].ordered;

        Item item;
        findItem(item_id, item);

        Price currentPrice = item.price(_store->getId(), size);

        grid->set(USE_NEXT, 0, number);
        grid->set(USE_CURR, 1, item.description());
        grid->set(USE_CURR, 2, size);
        grid->set(USE_CURR, 3, currentPrice.toString());
        grid->set(USE_CURR, 4, promoPrice.toString());
        grid->set(USE_CURR, 5, ordered.toString());
    }
    bool cancelled = progress->wasCancelled();
    progress->setProgress(_curr.items().size());
    delete progress;

    if (!cancelled) grid->print(this);
    delete grid;
}
Esempio n. 6
0
void
ServiceCharges::slotCalculate()
{
    QDate start = _start->getDate();
    QDate end = _end->getDate();
    int days = end - start + 1;

    // Validate data
    if (start.isNull()) {
	QString message = tr("A start date must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_start->setFocus();
	return;
    }
    if (end.isNull()) {
	QString message = tr("An end date must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_end->setFocus();
	return;
    }
    if (start > end) {
	QString message = tr("Invalid date range");
	QMessageBox::critical(this, tr("Error"), message);
	_start->setFocus();
	return;
    }

    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Select all customers
    vector<Customer> customers;
    CustomerSelect conditions;
    conditions.activeOnly = true;
    _quasar->db()->select(customers, conditions);

    // Get invoice terms
    _quasar->db()->invoiceTerms(_invoice_ids, _invoice_term_ids);

    // Setup progress dialog
    unsigned int custs = customers.size();
    QString message = tr("Calculating service charges...");
    QProgressDialog* progress = new QProgressDialog(message, tr("Cancel"),
						    custs, this, "foo", true);
    progress->setMinimumDuration(0);
    progress->setCaption(tr("Progress"));

    // Process each customer
    fixed totalCharges;
    _charges->clear();
    for (unsigned int i = 0; i < custs; ++i) {
	progress->setProgress(i);
	qApp->processEvents();
	if (progress->wasCancelled()) {
	    _charges->clear();
	    QApplication::restoreOverrideCursor();
	    QString message = tr("Service charge calculation cancelled");
	    QMessageBox::information(this, tr("Cancelled"), message);
	    return;
	}

	const Customer& customer = customers[i];
	if (customer.serviceCharge() == 0.0) continue;
	double dailyRate = customer.serviceCharge().toDouble() * 1000.0/365.0;

	// Get all transactions for customer
	GltxSelect conditions;
	conditions.activeOnly = true;
	conditions.card_id = customer.id();
	_quasar->db()->select(_gltxs, conditions);
	if (_gltxs.size() == 0) continue;

	// Remove all that don't effect card balance
	for (int k = _gltxs.size() - 1; k >= 0; --k) {
	    const Gltx& gltx = _gltxs[k];
	    if (gltx.cardTotal() != 0.0) continue;
	    _gltxs.erase(_gltxs.begin() + k);
	}

	// Sort by date
	std::sort(_gltxs.begin(), _gltxs.end());

	// Allocate unallocated payments
	for (unsigned int j = 0; j < _gltxs.size(); ++j) {
	    const Gltx& payment = _gltxs[j];
	    if (payment.cardTotal() >= 0.0) continue;
	    if (payment.cardTotal() == payment.paymentTotal()) continue;

	    fixed alloc = -(payment.cardTotal() - payment.paymentTotal());
	    for (unsigned int k = 0; k < _gltxs.size(); ++k) {
		Gltx& gltx = _gltxs[k];
		if (gltx.cardTotal() <= 0.0) continue;
		if (gltx.cardTotal() == gltx.paymentTotal()) continue;

		fixed pay = gltx.cardTotal() - gltx.paymentTotal();
		if (pay > alloc) pay = alloc;

		gltx.payments().push_back(PaymentLine(payment.id(), pay, 0.0));
		alloc -= pay;
		if (alloc == 0.0) break;
	    }

	    // If not all allocated then nothing left to allocate against
	    if (alloc != 0.0) break;
	}

	// Calculate service charge total
	double totalCharge = 0.0;
	for (unsigned int j = 0; j < _gltxs.size(); ++j) {
	    const Gltx& gltx = _gltxs[j];
	    if (gltx.cardTotal() < 0.0) continue;

	    for (int day = 0; day < days; ++day) {
	        fixed balance = balanceOn(gltx, start + day);
		double charge = balance.toDouble() * dailyRate;
		totalCharge += charge;
	    }
	}

	// Adjust and round
	fixed serviceCharge = totalCharge / 100000.0;
	serviceCharge.moneyRound();
	if (serviceCharge <= 0.0) continue;

	ListViewItem* item = new ListViewItem(_charges, customer.id());
	item->setValue(0, customer.name());
	item->setValue(1, serviceCharge);
	totalCharges += serviceCharge;
    }

    ListViewItem* item = new ListViewItem(_charges);
    item->isLast = true;
    item->setValue(0, "Total");
    item->setValue(1, totalCharges);

    progress->setProgress(custs);
    delete progress;

    QApplication::restoreOverrideCursor();
    message = tr("Service charge calculation is complete");
    QMessageBox::information(this, tr("Complete"), message);
}
Esempio n. 7
0
void
Journal::slotRealRefresh()
{
    if (_loading) return;
    _loading = true;
    setEnabled(false);
    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Disabled updates so that progress bar updating doesn't also do lists
    _general->setUpdatesEnabled(false);
    _disbursements->setUpdatesEnabled(false);
    _receipts->setUpdatesEnabled(false);
    _sales->setUpdatesEnabled(false);
    _purchases->setUpdatesEnabled(false);
    _inventory->setUpdatesEnabled(false);
    _all->setUpdatesEnabled(false);

    // Load accounts if needed
    if (_accounts.size() == 0) {
	_quasar->db()->select(_accounts, AccountSelect());
    }

    // Clear out old values
    _general->clearList();
    _disbursements->clearList();
    _receipts->clearList();
    _sales->clearList();
    _purchases->clearList();
    _inventory->clearList();
    _all->clearList();

    _lastStart = _from->getDate();
    _lastEnd = _to->getDate();
    int days = _lastEnd - _lastStart + 1;

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Loading transactions..."),
						    tr("Cancel"), days, this,
						    "Progress", true);
    progress->setMinimumDuration(0);
    progress->setCaption(tr("Progress"));

    for (int day = 0; day < days; ++day) {
	loadDate(_lastStart + day);

	progress->setProgress(day);
	qApp->processEvents();
	if (progress->wasCancelled()) {
	    // TODO: add cancelled line
	    break;
	}
    }

    progress->setProgress(days);
    delete progress;

    // Enable updates on lists
    _general->setUpdatesEnabled(true);
    _disbursements->setUpdatesEnabled(true);
    _receipts->setUpdatesEnabled(true);
    _sales->setUpdatesEnabled(true);
    _purchases->setUpdatesEnabled(true);
    _inventory->setUpdatesEnabled(true);
    _all->setUpdatesEnabled(true);

    QApplication::restoreOverrideCursor();
    setEnabled(true);
    _loading = false;
    _refreshPending = false;
}
Esempio n. 8
0
void
ItemInquiry::slotRefresh(QDate from, QDate to, Id store_id)
{
    if (loading) return;
    loading = true;
    needsRefresh = false;
    delete _grid;
    _grid = NULL;

    // Clear data
    list->clear();
    for (int label = 0; label < 10; ++label)
        labels[label]->setText(" ");

    // Get item to show and return if none
    Id item_id = search->getId();
    if (item_id == INVALID_ID) {
        loading = false;
        return;
    }

    setEnabled(false);
    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Get item information
    Item item;
    quasar->db()->lookup(item_id, item);

    fixed beginOnHand = 0.0;
    fixed beginCost = 0.0;
    fixed beginOnOrder = 0.0;
    fixed totalDebits = 0.0;
    fixed totalCredits = 0.0;

    labels[0]->setText(tr("Beginning Balance"));
    labels[1]->setText(tr("Total Increase"));
    labels[2]->setText(tr("Total Decrease"));
    labels[3]->setText(tr("Net Change"));
    labels[4]->setText(tr("Ending Balance"));

    // Get beginning balance
    if (!from.isNull())
        quasar->db()->itemGeneral(item.id(), "", store_id, from - 1,
                                  beginOnHand, beginCost, beginOnOrder);

    // Select transactions
    vector<Gltx> gltxs;
    vector<fixed> quantities;
    vector<fixed> ext_costs;
    vector<fixed> ext_prices;
    vector<bool> void_flags;
    quasar->db()->selectItem(item.id(), store_id, from, to, gltxs,
                             quantities, ext_costs, ext_prices, void_flags);

    // Setup grid
    _grid = new Grid(8);
    Grid* header = new Grid(1, _grid);
    TextFrame* text;
    text = new TextFrame(tr("Item Inquiry"), header);
    text->setFont(Font("Times", 24));
    header->set(USE_NEXT, 0, text);
    text = new TextFrame(item.number() + " " + item.description(), header);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    text = new TextFrame(DateValcon().format(from) + tr(" to ") +
                         DateValcon().format(to), header);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    header->setColumnWeight(0, 1);

    _grid->set(0, 0, 1, _grid->columns(), header, Grid::AllSides);
    _grid->set(USE_NEXT, 0, "");
    for (int column = 0; column < 8; ++column) {
        _grid->setColumnSticky(column, column < 4 ? Grid::Left : Grid::Right);
        _grid->setColumnPad(column, 5);
    }
    _grid->set(2, 0, tr("Type"));
    _grid->set(3, 0, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 1, tr("Id #"));
    _grid->set(3, 1, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 2, tr("Store"));
    _grid->set(3, 2, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 3, tr("Date"));
    _grid->set(3, 3, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 4, tr("Memo"));
    _grid->set(3, 4, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 5, tr("Debit"));
    _grid->set(3, 5, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 6, tr("Credit"));
    _grid->set(3, 6, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 7, tr("Voided?"));
    _grid->set(3, 7, new LineFrame(_grid), Grid::LeftRight);
    _grid->setHeaderRows(_grid->rows());

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Loading data..."),
            tr("Cancel"), gltxs.size(),
            this, "Progress", true);
    progress->setMinimumDuration(1000);
    progress->setCaption(tr("Progress"));

    // Process each transaction
    for (unsigned int i = 0; i < gltxs.size(); ++i) {
        const Gltx& gltx = gltxs[i];
        fixed ext_cost = ext_costs[i];
        // TODO: pick to show cost, qty, or price

        if (i % 50 == 0) {
            progress->setProgress(i);
            qApp->processEvents();
            if (progress->wasCancelled()) {
                break;
            }
        }

        // Don't show voided lines or quotes
        if (void_flags[i] || gltx.dataType() == DataObject::QUOTE)
            continue;

        Store store;
        quasar->db()->lookup(gltx.storeId(), store);

        ListViewItem* item = new ListViewItem(list, gltx.id());
        item->setValue(0, gltx.dataTypeName());
        item->setValue(1, gltx.number());
        item->setValue(2, store.number());
        item->setValue(3, gltx.postDate());
        item->setValue(4, gltx.memo());
        item->setValue(7, !gltx.isActive());

        _grid->set(USE_NEXT, 0, gltx.dataTypeName());
        _grid->set(USE_CURR, 1, gltx.number());
        _grid->set(USE_CURR, 2, store.number());
        _grid->set(USE_CURR, 3, DateValcon().format(gltx.postDate()));
        _grid->set(USE_CURR, 4, gltx.memo());
        _grid->set(USE_CURR, 7, gltx.isActive() ? " " : "x");

        // Correct sign based on type
        switch (gltx.dataType()) {
        case DataObject::INVOICE:
        case DataObject::RETURN:
            ext_cost = -ext_cost;
            break;
        default:
            break;
        }

        if (ext_cost >= 0.0) {
            item->setValue(5, ext_cost);
            _grid->set(USE_CURR, 5, MoneyValcon().format(ext_cost));
            if (gltx.isActive()) totalDebits += ext_cost;
        } else {
            item->setValue(6, -ext_cost);
            _grid->set(USE_CURR, 6, MoneyValcon().format(-ext_cost));
            if (gltx.isActive()) totalCredits += -ext_cost;
        }
    }
    progress->setProgress(gltxs.size());
    delete progress;

    // Set bottom totals
    fixed netChange = totalDebits - totalCredits;
    fixed endBalance = beginCost + netChange;

    MoneyValcon moneyValcon;
    labels[5]->setText(moneyValcon.format(beginCost));
    labels[6]->setText(moneyValcon.format(totalDebits));
    labels[7]->setText(moneyValcon.format(totalCredits));
    labels[8]->setText(moneyValcon.format(netChange));
    labels[9]->setText(moneyValcon.format(endBalance));

    _grid->set(USE_NEXT, 0, "");
    _grid->set(USE_NEXT, 0, 1, 5, tr("Beginning Balance"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(beginCost));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Total Debits"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(totalDebits));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Total Credits"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(totalCredits));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Net Change"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(netChange));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Ending Balance"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(endBalance));

    QApplication::restoreOverrideCursor();
    setEnabled(true);
    loading = false;
}