#include "weekcalendarwidget.h"
WeekCalendarWidget
::WeekCalendarWidget(QWidget *parent
) :{
this->setColumnCount(7);
this->setRowCount(2);
date
= QDate::currentDate();
this->verticalHeader()->hide();
this->horizontalHeader()->hide();
this->setSpan(0, 1, 1, 5);
str = "<";
tableItem = createItem(str);
this->setItem(0, 0, tableItem);
str = ">";
tableItem = createItem(str);
this->setItem(0, 6, tableItem);
/*
QWidget *asdsa = new WeekCalendarWidgetItem("0", "0");
this->setCellWidget(0, 1, asdsa);
*/
connect(this, SIGNAL(cellClicked(int,int)), this, SLOT(changeWeek(int, int)));
this
->horizontalHeader
()->setResizeMode
(QHeaderView::Stretch);
countForCalendar();
this->setRowHeight(1, 50);
}
void WeekCalendarWidget::changeWeek(int row, int column)
{
if (row==0 && column==0)
{
date = date.addDays(-7);
countForCalendar();
}
else if (row==0 && column==6)
{
date = date.addDays(7);
countForCalendar();
}
}
void WeekCalendarWidget::countForCalendar()
{
int weekNumber = date.weekNumber();
str
= "Year " + QString::number(date.
year()) + " Week " + QString::number(weekNumber
);
tableItem = createItem(str);
this->setItem(0, 1, tableItem);
str.setNum(date.day());
tableItem = createItem(str);
this->setItem(1, date.dayOfWeek()-1, tableItem);
int i = date2.dayOfWeek();
while (i>1)
{
date2 = date2.addDays(-1);
str.setNum(date2.day());
tableItem = createItem(str);
this->setItem(1, date2.dayOfWeek()-1, tableItem);
i = date2.dayOfWeek();
}
date2 = date;
i = date2.dayOfWeek();
while (i<7)
{
date2 = date2.addDays(1);
str.setNum(date2.day());
tableItem = createItem(str);
this->setItem(1, date2.dayOfWeek()-1, tableItem);
i = date2.dayOfWeek();
}
}
{
tableItem2->setTextAlignment(Qt::AlignCenter);
tableItem2->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
return tableItem2;
}
WeekCalendarWidget::~WeekCalendarWidget()
{
}
void WeekCalendarWidget::test(QWidgetList *lista)
{
asd = lista;
}
#include "weekcalendarwidget.h"
WeekCalendarWidget::WeekCalendarWidget(QWidget *parent) :
QTableWidget(parent)
{
this->setColumnCount(7);
this->setRowCount(2);
date = QDate::currentDate();
this->verticalHeader()->hide();
this->horizontalHeader()->hide();
this->setSpan(0, 1, 1, 5);
str = "<";
tableItem = createItem(str);
this->setItem(0, 0, tableItem);
str = ">";
tableItem = createItem(str);
this->setItem(0, 6, tableItem);
/*
QWidget *asdsa = new WeekCalendarWidgetItem("0", "0");
this->setCellWidget(0, 1, asdsa);
*/
connect(this, SIGNAL(cellClicked(int,int)), this, SLOT(changeWeek(int, int)));
this->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
countForCalendar();
this->setRowHeight(1, 50);
this->setSelectionMode(QAbstractItemView::SingleSelection);
}
void WeekCalendarWidget::changeWeek(int row, int column)
{
if (row==0 && column==0)
{
date = date.addDays(-7);
countForCalendar();
}
else if (row==0 && column==6)
{
date = date.addDays(7);
countForCalendar();
}
}
void WeekCalendarWidget::countForCalendar()
{
int weekNumber = date.weekNumber();
str = "Year " + QString::number(date.year()) + " Week " + QString::number(weekNumber);
tableItem = createItem(str);
this->setItem(0, 1, tableItem);
str.setNum(date.day());
tableItem = createItem(str);
this->setItem(1, date.dayOfWeek()-1, tableItem);
QDate date2 = date;
int i = date2.dayOfWeek();
while (i>1)
{
date2 = date2.addDays(-1);
str.setNum(date2.day());
tableItem = createItem(str);
this->setItem(1, date2.dayOfWeek()-1, tableItem);
i = date2.dayOfWeek();
}
date2 = date;
i = date2.dayOfWeek();
while (i<7)
{
date2 = date2.addDays(1);
str.setNum(date2.day());
tableItem = createItem(str);
this->setItem(1, date2.dayOfWeek()-1, tableItem);
i = date2.dayOfWeek();
}
}
QTableWidgetItem * WeekCalendarWidget::createItem(QString string)
{
QTableWidgetItem *tableItem2 = new QTableWidgetItem(string);
tableItem2->setTextAlignment(Qt::AlignCenter);
tableItem2->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
return tableItem2;
}
WeekCalendarWidget::~WeekCalendarWidget()
{
}
void WeekCalendarWidget::test(QWidgetList *lista)
{
asd = lista;
}
To copy to clipboard, switch view to plain text mode
#include "weekcalendarwidgetitem.h"
#include <QtGui>
{
date = date_par;
number = number_par;
}
void WeekCalendarWidgetItem
::paintEvent(QPaintEvent *event
) {
painter->drawText(this->geometry(), Qt::AlignTop, date);
painter->drawLine(this->geometry().topRight(), this->geometry().bottomLeft());
painter->drawText(this->geometry(), Qt::AlignBottom|Qt::AlignRight, number);
}
WeekCalendarWidgetItem::~WeekCalendarWidgetItem()
{
}
#include "weekcalendarwidgetitem.h"
#include <QtGui>
WeekCalendarWidgetItem::WeekCalendarWidgetItem(QString date_par, QString number_par, QWidget *parent)
: QWidget(parent)
{
date = date_par;
number = number_par;
}
void WeekCalendarWidgetItem::paintEvent(QPaintEvent *event)
{
painter = new QPainter(this);
painter->drawText(this->geometry(), Qt::AlignTop, date);
painter->drawLine(this->geometry().topRight(), this->geometry().bottomLeft());
painter->drawText(this->geometry(), Qt::AlignBottom|Qt::AlignRight, number);
}
WeekCalendarWidgetItem::~WeekCalendarWidgetItem()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks