void KOEditorGeneralTodo::dateChanged()
{
    KLocale *l = KGlobal::locale();
    QString dateTimeStr = "";

    if(mStartCheck->isChecked())
    {
        dateTimeStr += i18n("Start: %1").arg(
                           l->formatDate(mStartDateEdit->date()));
        if(mTimeButton->isChecked())
            dateTimeStr += QString(" %1").arg(
                               l->formatTime(mStartTimeEdit->getTime()));
    }

    if(mDueCheck->isChecked())
    {
        dateTimeStr += i18n("   Due: %1").arg(
                           l->formatDate(mDueDateEdit->date()));
        if(mTimeButton->isChecked())
            dateTimeStr += QString(" %1").arg(
                               l->formatTime(mDueTimeEdit->getTime()));
    }

    emit dateTimeStrChanged(dateTimeStr);
    QDateTime endDt(mDueDateEdit->date(), mDueTimeEdit->getTime());
    emit signalDateTimeChanged(endDt, endDt);
}
示例#2
0
/******************************************************************************
*  Return the alarm time text in the form "date time".
*/
QString AlarmListViewItem::alarmTimeText(const DateTime &dateTime) const
{
    KLocale *locale = KGlobal::locale();
    QString dateTimeText = locale->formatDate(dateTime.date(), true);
    if(!dateTime.isDateOnly())
    {
        dateTimeText += ' ';
        QString time = locale->formatTime(dateTime.time());
        if(mTimeHourPos == -2)
        {
            // Initialise the position of the hour within the time string, if leading
            // zeroes are omitted, so that displayed times can be aligned with each other.
            mTimeHourPos = -1;     // default = alignment isn't possible/sensible
            if(!QApplication::reverseLayout())     // don't try to align right-to-left languages
            {
                QString fmt = locale->timeFormat();
                int i = fmt.find(QRegExp("%[kl]"));   // check if leading zeroes are omitted
                if(i >= 0  &&  i == fmt.find('%'))    // and whether the hour is first
                    mTimeHourPos = i;             // yes, so need to align
            }
        }
        if(mTimeHourPos >= 0  && (int)time.length() > mTimeHourPos + 1
                &&  time[mTimeHourPos].isDigit()  &&  !time[mTimeHourPos + 1].isDigit())
            dateTimeText += '~';     // improve alignment of times with no leading zeroes
        dateTimeText += time;
    }
    return dateTimeText + ' ';
}
示例#3
0
QVariant DocumentModel::data(const QModelIndex &idx, int role) const
{   
  if(role == Qt::DisplayRole)
  {
    if(idx.column() == Document_LastModified ) {
      KLocale *locale = KGlobal::locale();
      QDateTime date = QSqlQueryModel::data(idx, role).toDateTime();
      return locale->formatDateTime( date, KLocale::ShortDate );
    } else if( idx.column() == Document_CreationDate ) {
      KLocale *locale = KGlobal::locale();
      QDate date = QSqlQueryModel::data( idx, role ).toDate();
      return locale->formatDate( date, KLocale::ShortDate );
    } else if(idx.column() == Document_ClientId ) {
      const QString uid = QSqlQueryModel::data( idx, role ).toString();
      return uid;
    } else if( idx.column() == Document_ClientName ) {
      QModelIndex uidIdx = idx.sibling( idx.row(), Document_ClientId );
      const QString uid = QSqlQueryModel::data( uidIdx, role ).toString();

      // kDebug() << "Checking for UID " << uid;
      if( uid.isEmpty() ) return "";

      if( mAddresses.contains( uid ) ) {
        if( mAddresses.value(uid).isEmpty() ) {
          // empty address means that there is no valid entry in this addressbook
          return i18n("not found");
        }
        const QString realName = mAddresses.value(uid).realName();

        // kDebug() << "returning " << realName;
        return realName;
      } else {
        mAddressProvider->getAddressee( uid );
      }
      return i18n("retrieving...");
    }
  } else if( role == RawTypes ) {
    if(idx.column() == Document_LastModified ) {
      return QSqlQueryModel::data( idx, Qt::DisplayRole ).toDateTime();
    } else if( idx.column() == Document_CreationDate ) {
      return QSqlQueryModel::data( idx, Qt::DisplayRole ).toDate();
    }
  } else if( role == Qt::SizeHintRole ) {
    QFont f = QSqlQueryModel::data(idx, Qt::FontRole ).value<QFont>();
    QFontMetrics fm(f);
    int h = fm.height();

    return QSize( 0, h + 4 );
  }
  return QSqlQueryModel::data(idx, role);
}
示例#4
0
void KraftViewRO::setup( DocGuardedPtr doc )
{
    KraftViewBase::setup( doc );

    if ( !doc ) return;

    KLocale *locale = doc->locale();
    if ( !locale ) locale = KGlobal::locale();

    // do stuff like open a template and render values into it.
    KStandardDirs stdDirs;
    QString templFileName = QString( "kraftdoc_ro.trml" );
    QString findFile = "kraft/reports/" + templFileName;

    QString tmplFile = stdDirs.findResource( "data", findFile );


    QByteArray kraftHome = qgetenv("KRAFT_HOME");

    if( !kraftHome.isEmpty() ) {
        QString file = QString( "%1/reports/kraftdoc_ro.trml").arg(QString::fromLocal8Bit(kraftHome));
        QFileInfo fi(file);
        if( fi.exists() && fi.isReadable() ) {
            tmplFile = file;
        }
    }
    if( tmplFile.isEmpty() ) {
        kDebug() << "Could not find template to render ro view of document.";
        return;
    }


    TextTemplate tmpl( tmplFile );
    if( !tmpl.open() ) {
        return;
    }
    tmpl.setValue( DOC_RO_TAG( "HEADLINE" ), doc->docType() + " " + doc->ident() );
    tmpl.setValue( DOC_RO_TAG( "DATE" ), locale->formatDate( doc->date(), KLocale::ShortDate ) );
    tmpl.setValue( DOC_RO_TAG( "DOC_TYPE" ),  doc->docType() );
    QString address = doc->address();
    address.replace( '\n', "<br/>" );
    tmpl.setValue( DOC_RO_TAG( "ADDRESS" ), address );
    tmpl.setValue( DOC_RO_TAG( "DOCNO" ), doc->ident() );
    tmpl.setValue( DOC_RO_TAG( "PRETEXT" ), doc->preText() );
    tmpl.setValue( DOC_RO_TAG( "POSTTEXT" ), doc->postText() );
    tmpl.setValue( DOC_RO_TAG( "SALUT" ), doc->salut() );
    tmpl.setValue( DOC_RO_TAG( "GOODBYE" ), doc->goodbye() );


    DocPositionList positions = doc->positions();

    // check the tax settings: If all items have the same settings, its not individual.
    bool individualTax = false;
    int ttype = -1;
    foreach( DocPositionBase *dp, positions  ) {
        if( ttype == -1 ) {
            ttype = dp->taxType();
        } else {
            if( ttype != dp->taxType() ) { // different from previous one?
                individualTax = true;
                break;
            }
        }
    }

    int pos = 1;
    int taxFreeCnt = 0;
    int reducedTaxCnt = 0;
    int fullTaxCnt = 0;

    QString docType = doc->docType();
    DocType dt(docType);

    foreach( DocPositionBase *dpb, positions ) {
        DocPosition *dp = static_cast<DocPosition*>(dpb);
        tmpl.createDictionary( "ITEMS" );

        tmpl.setValue( "ITEMS", "NUMBER", QString::number( pos++ ) );
        tmpl.setValue( "ITEMS", "TEXT", dp->text() );
        tmpl.setValue( "ITEMS", "AMOUNT", locale->formatNumber( dp->amount() ) );
        tmpl.setValue( "ITEMS", "UNIT", dp->unit().einheit( dp->amount() ) );
        double singlePrice = dp->unitPrice().toDouble();

        if( dt.pricesVisible() ) {
            tmpl.createSubDictionary("ITEMS", "PRICE_DISPLAY");
            tmpl.setValue( "PRICE_DISPLAY", "SINGLE_PRICE", locale->formatMoney( singlePrice ) );
            QString style( "positive" );
            if ( singlePrice < 0 ) {
                style = "negative";
            }

            tmpl.setValue( "PRICE_DISPLAY", "PRICE_STYLE", style );

            tmpl.setValue( "PRICE_DISPLAY", "PRICE", locale->formatMoney( dp->overallPrice().toDouble() ) );
        }
#if 0
        QString taxType;
        if( individualTax ) {
            if( dp->taxType() == 1 ) {
                taxFreeCnt++;
                taxType = "TAX_FREE";
            } else if( dp->taxType() == 2 ) {
                taxType = "REDUCED_TAX";
                reducedTaxCnt++;
            } else {
                // ATTENTION: Default for all non known tax types is full tax.
                fullTaxCnt++;
                taxType = "FULL_TAX";
            }
        }
#endif
    }
示例#5
0
void CalPrintYear::print( QPainter &p, int width, int height )
{
  QRect headerBox( 0, 0, width, headerHeight() );
  const KCalendarSystem *calsys = calendarSystem();
  KLocale *locale = KGlobal::locale();
  if ( !calsys || !locale ) {
    return;
  }

  QDate start;
  calsys->setYMD( start, mYear, 1, 1 );

  // Determine the nr of months and the max nr of days per month (dependent on
  // calendar system!!!!)
  QDate temp( start );
  int months = calsys->monthsInYear( start );
  int maxdays = 1;
  for ( int i = 1; i< months; ++i ) {
    maxdays = qMax( maxdays, temp.daysInMonth() );
    temp = calsys->addMonths( temp, 1 );
  }

  // Now determine the months per page so that the printout fits on
  // exactly mPages pages
  int monthsPerPage = ( months - 1 ) / mPages + 1;
  int pages = ( months - 1 ) / monthsPerPage + 1;
  int thismonth = 0;
  temp = start;
  for ( int page = 0; page < pages; ++page ) {
    if ( page > 0 ) {
      mPrinter->newPage();
    }
    QDate end( calsys->addMonths( start, monthsPerPage ) );
    end = calsys->addDays( end, -1 );
    QString stdate = locale->formatDate( start );
    QString endate = locale->formatDate( end );
    QString title;
    if ( orientation() == QPrinter::Landscape ) {
      title = i18nc( "date from - to", "%1 - %2", stdate, endate );
    } else {
      title = i18nc( "date from -\nto", "%1 -\n%2", stdate, endate );
    }
    drawHeader( p, title, calsys->addMonths( start, -1 ),
                calsys->addMonths( start, monthsPerPage ), headerBox );

    QRect monthesBox( headerBox );
    monthesBox.setTop( monthesBox.bottom() + padding() );
    monthesBox.setBottom( height );

    drawBox( p, BOX_BORDER_WIDTH, monthesBox );
    float monthwidth = float( monthesBox.width() ) / float( monthsPerPage );

    for ( int j=0; j<monthsPerPage; ++j ) {
      if ( ++thismonth > months ) {
        break;
      }
      int xstart = int( j * monthwidth + 0.5 );
      int xend = int( ( j + 1 ) * monthwidth + 0.5 );
      QRect monthBox( xstart, monthesBox.top(), xend - xstart, monthesBox.height() );
      drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents );

      temp = calsys->addMonths( temp, 1 );
    }
    start = calsys->addMonths( start, monthsPerPage );
  }
}
示例#6
0
/**
 * Deal with right click's
 */
void KBinaryClock::openContextMenu() {
		bool bImmutable = config()->isImmutable();

		KPopupMenu *menu = new KPopupMenu();
		menu->insertTitle( SmallIcon( "clock" ), i18n( "KBinaryClock" ) );

		KLocale *loc = KGlobal::locale();
		QDateTime dt = QDateTime::currentDateTime();

		KPopupMenu *copyMenu = new KPopupMenu( menu );
		copyMenu->insertItem(loc->formatDateTime(dt), 201);
		copyMenu->insertItem(loc->formatDate(dt.date()), 202);
		copyMenu->insertItem(loc->formatDate(dt.date(), true), 203);
		copyMenu->insertItem(loc->formatTime(dt.time()), 204);
		copyMenu->insertItem(loc->formatTime(dt.time(), true), 205);
		copyMenu->insertItem(dt.date().toString(), 206);
		copyMenu->insertItem(dt.time().toString(), 207);
		copyMenu->insertItem(dt.toString(), 208);
		connect( copyMenu, SIGNAL( activated(int) ), this, SLOT( slotCopyMenuActivated(int) ) );

		if (!bImmutable)
		{
				if (kapp->authorize("user/root"))
				{
						menu->insertItem(SmallIcon("date"), i18n("&Adjust Date && Time..."), 103, 4);
				}
				menu->insertItem(SmallIcon("kcontrol"), i18n("Date && Time &Format..."), 104, 5);
		}

		menu->insertItem(SmallIcon("editcopy"), i18n("C&opy to Clipboard"), copyMenu, 105, 6);
		if (!bImmutable)
		{
				menu->insertSeparator(7);
				menu->insertItem(SmallIcon("configure"), i18n("&Configure KBinaryClock..."), 102, 8);
		}
		int result = menu->exec( QCursor::pos() );

		KProcess proc;
		switch (result) {
	case 102:
		preferences();
		break;
	case 103:
		proc << locate("exe", "kdesu");
		proc << "--nonewdcop";
		proc << QString("%1 clock --lang %2")
				.arg(locate("exe", "kcmshell"))
				.arg(KGlobal::locale()->language());
		proc.start(KProcess::DontCare);
		break;
	case 104:
		proc << locate("exe", "kcmshell");
		proc << "language";
					proc.start(KProcess::DontCare);
		break;
	case 110:
		preferences();
		break;
		} /* switch() */
		delete menu;
}