void KApplicationStatus::breathe(int ms)
{
	if(g_pApp->m_nowTime >= m_appData->expireTime)
	{
		KDatetime nowDate(g_pApp->m_nowTime);
		KLocalDatetime ldt = nowDate.GetLocalTime();//获取当前时间
		m_appData->yyyy_mm_dd = ldt.year * 10000 + ldt.month * 100 + ldt.day;
		m_appData->expireTime = KDatetime::nextDayFirstSecond((TIME_T)nowDate.Time());
		m_appData->daySequence = 0;
	}
}
示例#2
0
void NotifyWindow::updateNotifyDisplay() {
	if (!item) return;

	int32 w = st::notifyWidth, h = st::notifyHeight;
	QImage img(w * cIntRetinaFactor(), h * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
	if (cRetina()) img.setDevicePixelRatio(cRetinaFactor());
	img.fill(st::notifyBG->c);

	{
		QPainter p(&img);
		p.fillRect(0, 0, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder->b);
		p.fillRect(w - st::notifyBorderWidth, 0, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder->b);
		p.fillRect(st::notifyBorderWidth, h - st::notifyBorderWidth, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder->b);
		p.fillRect(0, st::notifyBorderWidth, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder->b);

		if (cNotifyView() <= dbinvShowName) {
			if (history->peer->photo->loaded()) {
				p.drawPixmap(st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), history->peer->photo->pix(st::notifyPhotoSize));
			} else {
				MTP::clearLoaderPriorities();
				peerPhoto = history->peer->photo;
				peerPhoto->load(true, true);
			}
		} else {
			static QPixmap icon = QPixmap::fromImage(App::wnd()->iconLarge().scaled(st::notifyPhotoSize, st::notifyPhotoSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
			p.drawPixmap(st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), icon);
		}

		int32 itemWidth = w - st::notifyPhotoPos.x() - st::notifyPhotoSize - st::notifyTextLeft - st::notifyClosePos.x() - st::notifyClose.width;

		QRect rectForName(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyTextTop, itemWidth, st::msgNameFont->height);
		if (cNotifyView() <= dbinvShowName) {
			if (history->peer->chat) {
				p.drawPixmap(QPoint(rectForName.left() + st::dlgChatImgLeft, rectForName.top() + st::dlgChatImgTop), App::sprite(), st::dlgChatImg);
				rectForName.setLeft(rectForName.left() + st::dlgChatImgSkip);
			}
		}

		QDateTime now(QDateTime::currentDateTime()), lastTime(item->date);
		QDate nowDate(now.date()), lastDate(lastTime.date());
		QString dt = lastTime.toString(qsl("hh:mm"));
		int32 dtWidth = st::dlgHistFont->m.width(dt);
		rectForName.setWidth(rectForName.width() - dtWidth - st::dlgDateSkip);
		p.setFont(st::dlgDateFont->f);
		p.setPen(st::dlgDateColor->p);
		p.drawText(rectForName.left() + rectForName.width() + st::dlgDateSkip, rectForName.top() + st::dlgHistFont->ascent, dt);

		if (cNotifyView() <= dbinvShowPreview) {
			const HistoryItem *textCachedFor = 0;
			Text itemTextCache(itemWidth);
			bool active = false;
			item->drawInDialog(p, QRect(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height, itemWidth, 2 * st::dlgFont->height), active, textCachedFor, itemTextCache);
		} else {
			static QString notifyText = st::dlgHistFont->m.elidedText(lang(lng_notification_preview), Qt::ElideRight, itemWidth);
			p.setPen(st::dlgSystemColor->p);
			p.drawText(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height + st::dlgHistFont->ascent, notifyText);
		}

		p.setPen(st::dlgNameColor->p);
		if (cNotifyView() <= dbinvShowName) {
			history->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
		} else {
			p.setFont(st::msgNameFont->f);
			static QString notifyTitle = st::msgNameFont->m.elidedText(lang(lng_notification_title), Qt::ElideRight, rectForName.width());
			p.drawText(rectForName.left(), rectForName.top() + st::msgNameFont->ascent, notifyTitle);
		}
	}

	pm = QPixmap::fromImage(img);
	update();
}
示例#3
0
void TodoList::paintEvent(QPaintEvent *){
    QPainter painter;
    painter.begin(this);

    if(state == WINSTATE::LIST){        
        //标题名称的临时变量
        char temp[128];
        string text;
        text += "<  ";
        int viewYear = viewDate.year;
        int viewMonth = viewDate.month;

        string viewType = "全部";
        string nullText = "出去玩吧 ≥▽≤";
        if(viewState == VIEWSTATE::UNDONE){
            viewType = "未完成";
            nullText = "出去玩吧 ^o^";
        }else{
            if(viewState == VIEWSTATE::WARN){
                viewType = "提醒";
                nullText = "没有提醒 ~";
            }
        }

        sprintf(temp,"%d/%.2d - %s",viewYear,viewMonth,viewType.c_str());
        text += temp;
        text += "  >";

        ui->titleBox->setText(QString::fromStdString(text));


        int posX = 16,posY = 60;
        posY += moveY;
        int paintX = 0,paintY = 0;

        //用于显示具体日期,这里将同一天的事件归为一类
        int lastDay = 0;

        bool haveTodo = false;
        bool first = true;
        indexSize = 0;
        int todoSize = pa.GetListSize(viewYear,viewMonth);

        QDateTime qDateTime = QDateTime::currentDateTime();
        QDate qDate= qDateTime.date();
        QTime qTime = qDateTime.time();
        Date nowDate(qDate.year(),qDate.month(),qDate.day(),qTime.hour(),qTime.minute(),qTime.second());

        for(int i=0;i<todoSize;i++){

          paintX = indexPosX[indexSize];
          TodoItem &item = pa.GetItem(i,viewYear,viewMonth);
          Date date = item.GetTime();

          if(viewState == VIEWSTATE::UNDONE){
              if(item.HaveDone())continue;
          }else if(viewState == VIEWSTATE::WARN){
              int warnTime = item.GetWarnTime();
              if(warnTime == 0 || date.GetTime() - nowDate.GetTime() > warnTime){
                  continue;
              }
          }
          //if(date.month != viewMonth || date.year != viewYear)continue;

          haveTodo = true;

          if(date.day != lastDay){
              lastDay = date.day;
              //优化渲染效率
              if(posY + 59 +paintY + 50 > 0){
                  //绘制时间文字
                  painter.setPen(QPen(Qt::gray));
                  painter.setFont(sFont);
                  char dateText[128];
                  static string weekStr[7] = {"日","一","二","三","四","五","六"};
                  sprintf(dateText,"%d年%.2d月%.2d日 星期%s   +",date.year,date.month,date.day,weekStr[date.GetWeek()].c_str());
                  painter.drawText(posX + 80 + paintX,posY - 21 + paintY,343,70,Qt::AlignBottom,QString::fromStdString(dateText));
                  painter.setPen(QPen(Qt::black));

                  if(!first)painter.drawPixmap(posX + 26,posY - 40 + paintY,8,60,line);//圆圈上方线条


                  painter.drawPixmap(posX + 9 + paintX,posY + 20 + paintY,40,40,circle);
                  char dayText[4];
                  sprintf(dayText,"%.2d",date.day);
                  painter.drawText(posX + 16 + paintX,posY + 14 + paintY,40,40,Qt::AlignBottom,QString::fromStdString(dayText));

                  painter.drawPixmap(posX + 26,posY + 59 + paintY,8,50,line); //圆圈下方线条
              }

              first = false;

              if(indexSize < 128)indexID[indexSize ++] = -1;

              paintY += 80;
          }

          paintX = indexPosX[indexSize];

          if(posY - 26 + paintY + 70 > 0){
              //绘制圆点上下直线
              painter.drawPixmap(posX + 26,posY + 20 + paintY,8,10,line);//圆点上方
              painter.drawPixmap(posX + 26,posY + 36 + paintY,8,65,line);//圆点下方
              //Todo框
              painter.drawPixmap(posX + 23 + paintX,posY + paintY,343,70,boxes[item.GetLevel()]);

              //勾Todo Havedone
              if(item.HaveDone())
                  painter.drawPixmap(posX + 68 + paintX,posY + paintY + 22,25,25,checkPic);

              //绘制Todo名称
              painter.setPen(QPen(Qt::black));
              painter.setFont(font);
              painter.drawText(posX + 113 + paintX,posY - 21 + paintY,343,70,Qt::AlignBottom,QString::fromStdString(item.GetName()));

              //左侧Todo时间
              painter.setPen(QPen(Qt::gray));
              painter.setFont(dateFont);
              char dateText[16];
              sprintf(dateText,"%.2d:%.2d",date.hour,date.minute);
              painter.drawText(posX - 12 + paintX,posY - 26 + paintY,343,70,Qt::AlignBottom,QString::fromStdString(dateText));
          }

          if(indexSize < 128)indexID[indexSize ++] = i; //记录对应todo的id号

          paintY += 80;
          //强行停止渲染
          if(posY + 20 + paintY > 600)break;
        }

        lastDateY = -(paintY);

        if(!haveTodo){
            painter.setPen(QPen(Qt::gray));
            painter.setFont(font);
            painter.drawText(posX + 100,posY - 21,400,70,Qt::AlignBottom,QString::fromStdString(nullText));
        }

    }
    painter.end();
}
示例#4
0
void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
	_shortPollRequest = 0;
	setLoading(false);

	auto availCurrent = st::boxWideWidth - st::sessionPadding.left() - st::sessionTerminateSkip;
	auto availOther = availCurrent - st::sessionTerminate.iconPosition.x();// -st::sessionTerminate.width - st::sessionTerminateSkip;

	_list.clear();
	if (result.type() != mtpc_account_authorizations) {
		return;
	}
	auto &v = result.c_account_authorizations().vauthorizations.c_vector().v;
	_list.reserve(v.size());

	const CountriesByISO2 &countries(countriesByISO2());

	for_const (auto &auth, v) {
		if (auth.type() != mtpc_authorization) {
			continue;
		}
		auto &d = auth.c_authorization();
		Data data;
		data.hash = d.vhash.v;

		QString appName, appVer = qs(d.vapp_version), systemVer = qs(d.vsystem_version), deviceModel = qs(d.vdevice_model);
		if (d.vapi_id.v == 2040 || d.vapi_id.v == 17349) {
			appName = (d.vapi_id.v == 2040) ? qstr("Telegram Desktop") : qstr("Telegram Desktop (GitHub)");
		//	if (systemVer == qstr("windows")) {
		//		deviceModel = qsl("Windows");
		//	} else if (systemVer == qstr("os x")) {
		//		deviceModel = qsl("OS X");
		//	} else if (systemVer == qstr("linux")) {
		//		deviceModel = qsl("Linux");
		//	}
			if (appVer == QString::number(appVer.toInt())) {
				int32 ver = appVer.toInt();
				appVer = QString("%1.%2").arg(ver / 1000000).arg((ver % 1000000) / 1000) + ((ver % 1000) ? ('.' + QString::number(ver % 1000)) : QString());
			} else {
				appVer = QString();
			}
		} else {
			appName = qs(d.vapp_name);// +qsl(" for ") + qs(d.vplatform);
			if (appVer.indexOf('(') >= 0) appVer = appVer.mid(appVer.indexOf('('));
		}
		data.name = appName;
		if (!appVer.isEmpty()) data.name += ' ' + appVer;
		data.nameWidth = st::sessionNameFont->width(data.name);

		QString country = qs(d.vcountry), platform = qs(d.vplatform);
		//CountriesByISO2::const_iterator j = countries.constFind(country);
		//if (j != countries.cend()) country = QString::fromUtf8(j.value()->name);

		MTPint active = d.vdate_active.v ? d.vdate_active : d.vdate_created;
		data.activeTime = active.v;

		data.info = qs(d.vdevice_model) + qstr(", ") + (platform.isEmpty() ? QString() : platform + ' ') + qs(d.vsystem_version);
		data.ip = qs(d.vip) + (country.isEmpty() ? QString() : QString::fromUtf8(" \xe2\x80\x93 ") + country);
		if (!data.hash || (d.vflags.v & 1)) {
			data.active = lang(lng_sessions_header);
			data.activeWidth = st::sessionWhenFont->width(lang(lng_sessions_header));
			int32 availForName = availCurrent - st::sessionPadding.right() - data.activeWidth;
			if (data.nameWidth > availForName) {
				data.name = st::sessionNameFont->elided(data.name, availForName);
				data.nameWidth = st::sessionNameFont->width(data.name);
			}
			data.infoWidth = st::sessionInfoFont->width(data.info);
			if (data.infoWidth > availCurrent) {
				data.info = st::sessionInfoFont->elided(data.info, availCurrent);
				data.infoWidth = st::sessionInfoFont->width(data.info);
			}
			data.ipWidth = st::sessionInfoFont->width(data.ip);
			if (data.ipWidth > availCurrent) {
				data.ip = st::sessionInfoFont->elided(data.ip, availCurrent);
				data.ipWidth = st::sessionInfoFont->width(data.ip);
			}
			_current = data;
		} else {
			QDateTime now(QDateTime::currentDateTime()), lastTime(date(active));
			QDate nowDate(now.date()), lastDate(lastTime.date());
			QString dt;
			if (lastDate == nowDate) {
				data.active = lastTime.toString(cTimeFormat());
			} else if (lastDate.year() == nowDate.year() && lastDate.weekNumber() == nowDate.weekNumber()) {
				data.active = langDayOfWeek(lastDate);
			} else {
				data.active = lastDate.toString(qsl("d.MM.yy"));
			}
			data.activeWidth = st::sessionWhenFont->width(data.active);
			int32 availForName = availOther - st::sessionPadding.right() - data.activeWidth;
			if (data.nameWidth > availForName) {
				data.name = st::sessionNameFont->elided(data.name, availForName);
				data.nameWidth = st::sessionNameFont->width(data.name);
			}
			data.infoWidth = st::sessionInfoFont->width(data.info);
			if (data.infoWidth > availOther) {
				data.info = st::sessionInfoFont->elided(data.info, availOther);
				data.infoWidth = st::sessionInfoFont->width(data.info);
			}
			data.ipWidth = st::sessionInfoFont->width(data.ip);
			if (data.ipWidth > availOther) {
				data.ip = st::sessionInfoFont->elided(data.ip, availOther);
				data.ipWidth = st::sessionInfoFont->width(data.ip);
			}

			_list.push_back(data);
			for (int32 i = _list.size(); i > 1;) {
				--i;
				if (_list.at(i).activeTime > _list.at(i - 1).activeTime) {
					qSwap(_list[i], _list[i - 1]);
				}
			}
		}
	}
	_inner->listUpdated();

	update();

	_shortPollTimer->start(SessionsShortPollTimeout);
}