void MyMoneyReport::validDateRange ( QDate& _db, QDate& _de )
{
  _db = fromDate();
  _de = toDate();

  // if either begin or end date are invalid we have one of the following
  // possible date filters:
  //
  // a) begin date not set - first transaction until given end date
  // b) end date not set   - from given date until last transaction
  // c) both not set       - first transaction until last transaction
  //
  // If there is no transaction in the engine at all, we use the current
  // year as the filter criteria.

  if ( !_db.isValid() || !_de.isValid() ) {
    QValueList<MyMoneyTransaction> list = MyMoneyFile::instance()->transactionList ( *this );
    QDate tmpBegin, tmpEnd;

    if ( !list.isEmpty() ) {
      qHeapSort ( list );
      tmpBegin = list.front().postDate();
      tmpEnd = list.back().postDate();
    } else {
      tmpBegin = QDate ( QDate::currentDate().year(), 1, 1 ); // the first date in the file
      tmpEnd = QDate ( QDate::currentDate().year(), 12, 31 );// the last date in the file
    }
    if ( !_db.isValid() )
      _db = tmpBegin;
    if ( !_de.isValid() )
      _de = tmpEnd;
  }
  if ( _db > _de )
    _db = _de;
}
Exemple #2
0
void KstEditViewObjectDialogI::fillPenStyleWidget(QComboBox* widget) {
  QRect rect = widget->style().querySubControlMetrics(QStyle::CC_ComboBox, 
                                                      widget, 
                                                      QStyle::SC_ComboBoxEditField);
  rect.setLeft(rect.left() + 2);
  rect.setRight(rect.right() - 2);
  rect.setTop(rect.top() + 2);
  rect.setBottom(rect.bottom() - 2);

  // fill the combo with pen styles
  QPixmap ppix(rect.width(), rect.height());
  QPainter pp(&ppix);
  QPen pen(Qt::black, 0);

  widget->clear(); 
  
  QValueList<Qt::PenStyle> styles;
  styles.append(Qt::SolidLine);
  styles.append(Qt::DashLine);
  styles.append(Qt::DotLine);
  styles.append(Qt::DashDotLine);
  styles.append(Qt::DashDotDotLine);
  
  while (!styles.isEmpty()) {
    pen.setStyle(styles.front());
    pp.setPen(pen);
    pp.fillRect( pp.window(), QColor("white"));
    pp.drawLine(1,ppix.height()/2,ppix.width()-1, ppix.height()/2);
    widget->insertItem(ppix);
    styles.pop_front();
  }
}
cTexture *cAsciiFonts::buildText(unsigned char font, const QCString &text, unsigned short hueid, bool shaded, enTextAlign align, bool hueAll) {
	if (font > 9) {
		font = 3; // Default back to font 3 if the font is invalid
	}

	unsigned int width = 0; // Total width of the text	
	unsigned int height = this->height[font]; // Total height of the text
	unsigned int lineWidth = 0; // Length of the current line
	unsigned int lines = 1; // Number of lines
	QValueList<unsigned int> lineWidths; // Vector with the lengths of lines
	
	// Iterate over the string once to get the width of the string
	QCString::ConstIterator it;
	for (it = text.begin(); it != text.end(); ++it) {
		if (*it == '\n') {
			lines += 1;
			if (lineWidth > width) {
				width = lineWidth;
			}
			lineWidths.append(lineWidth);
			lineWidth = 0;
		} else {
			cSurface *ch = getCharacter(font, *it);
	
			if (ch) {
				lineWidth += ch->width(); // Increase the width of the text
			}
		}
	}

	if (lineWidth > 0) {
		lineWidths.append(lineWidth);

		if (lineWidth > width) {
			width = lineWidth;
		}
	}

	unsigned int baseline = height; // Store the baseline
	height = lines * height; // Increase the height of the text	

	cSurface *surface = 0; // The resulting text line

	if (width > 0) {
		surface = new cSurface(width, height);
		surface->clear(); // Clear the background of the surface

		// Start copying the characters over
		int destx = 0;
		int desty = 0;
		switch (align) {
			case ALIGN_LEFT:
				destx = 0; // Start on the left border
				break;
			case ALIGN_CENTER:
				destx = (width - lineWidths.front()) >> 1; // Take whats left of the total width and divide it into two
				break;
			case ALIGN_RIGHT:
				destx = (width - lineWidths.front()); // Take the right part and use it as an offset
				break;
		}
		lineWidths.pop_front();

		for (it = text.begin(); it != text.end(); ++it) {
			if (*it == '\n') {
				if (!lineWidths.isEmpty()) {
					switch (align) {
						case ALIGN_LEFT:
							destx = 0; // Start on the left border
							break;
						case ALIGN_CENTER:
							destx = (width - lineWidths.front()) >> 1; // Take whats left of the total width and divide it into two
							break;
						case ALIGN_RIGHT:
							destx = (width - lineWidths.front()); // Take the right part and use it as an offset
							break;
					}
					lineWidths.pop_front();
				}
				baseline += this->height[font];
			} else {
				cSurface *ch = getCharacter(font, *it);
				if (ch) {
					desty = baseline - ch->height();
					// MemCpy Line by Line
					for (int yl = 0; yl < ch->height(); ++yl) {
						unsigned char *src = ch->scanline(yl);
						unsigned char *dest = surface->scanline(yl + desty) + destx * 4;
						memcpy(dest, src, ch->width() * 4);
					}
					destx += ch->width(); // Increase for the next draw
				}
			}
		}