#include "calendar.h" #include #include #include #include #include #include "draglabel.h" calendar::calendar(QWidget *parent):QCalendarWidget(parent) { drop_open = 1; m_outlinePen.setColor(Qt::red); m_transparentBrush.setColor(Qt::blue); setAcceptDrops(true); QObject::connect(this,SIGNAL(activated(const QDate &)),this,SLOT(addNote(const QDate &))); dir = "A:\\mycode\\file\\"; } calendar::~calendar() { } void calendar::fixon() { /*XRectangle w; w.x = 0; w.y = 0; w.height = height(); w.width = width(); XShapeCombineRectangles(QX11Info::display(),winId(),ShapeInput,0,0,w,0,ShapeSet,YXBanded);*/ } void calendar::fixoff() { /* XRectangle w; w.x = 0; w.y = 0; w.height = height(); w.width = width(); XShapeCombineRectangles(QX11Info::display(),winId(),ShapeInput,0,0,w,1,ShapeSet,YXBanded);*/ } void calendar::acdropt() { qDebug("setACD true"); setAcceptDrops(true); } void calendar::acdropf() { qDebug("setACD false"); setAcceptDrops(false); } void calendar::get_day_edit_changed(QDate date,dateinfo info) { qDebug("00159"); qDebug("R%d",info.get_back_ground().red()); info.sort(); if(dates.contains(date)) { int index = dates.indexOf(date); todolist.replace(index, info); } else { dates.append(date); todolist.append(info); } repaint(); } void calendar::addNote( const QDate &date ) { qDebug()<<"come in addNote"<setPen(m_outlinePen); painter->setBrush(m_transparentBrush); painter->drawRect(rect.adjusted(0, 0, -1, -1)); painter->drawText(rect,stringtmp); } } } void calendar::dragEnterEvent(QDragEnterEvent *event) { if(!drop_open)return; //如果为文件,则支持拖放 if (event->mimeData()->hasFormat("text/uri-list")) event->acceptProposedAction(); } //当用户放下这个文件后,就会触发dropEvent事件 void calendar::dropEvent(QDropEvent *event) { if(!drop_open)return; if(selectedDate().isNull()) { QMessageBox::about(NULL, tr("Error"), tr("No date has been selected!")); return; } qDebug("drop"); QList urls = event->mimeData()->urls(); if(urls.isEmpty()) return; foreach(QUrl url, urls) { file_name = url.path().mid(1,url.path().count()-1); qDebug()<pos(); QMimeData *QD = new QMimeData; QList urls; urls.append(QUrl::fromLocalFile(file_name)); QD->setUrls(urls); //QApplication::clipboard()->setMimeData(QD); QDrag *drag = new QDrag(this); drag->setMimeData(QD); drag->start(); qDebug()<