void PicViewerWindow::dropEvent(QDropEvent *event) { QList<QUrl> urls = event->mimeData()->urls(); if (urls.isEmpty()) return; QString fileName = urls.first().toLocalFile(); if (fileName.isEmpty()) return; if(fileName.toLower().endsWith(".jpg")|| fileName.toLower().endsWith(".jpeg")|| fileName.toLower().endsWith(".png")|| fileName.toLower().endsWith(".gif")|| fileName.toLower().endsWith(".bmp")) { openPic(fileName);//仅处理一个文件 } }
/*--------------------------------------- Private functions -----------------------------------------*/ void MainWindow::createActions(){ newDrawAction = new QAction(tr("&New"), this); newDrawAction->setIcon(QIcon(":/icon/newFile6.png")); newDrawAction->setShortcut(QKeySequence::New); newDrawAction->setStatusTip(tr("Create a new drawing")); connect(newDrawAction, SIGNAL(triggered()), this, SLOT(newEdit())); openPicAction = new QAction(tr("&Open"), this); openPicAction->setIcon(QIcon(":/icon/newFile7.png")); openPicAction->setShortcut(QKeySequence::Open); openPicAction->setStatusTip(tr("Open an existing pic")); connect(openPicAction, SIGNAL(triggered()), this, SLOT(openPic())); for(int i = 0;i < MaxRecentFiles;i ++){ recentFileActions[i] = new QAction(this); recentFileActions[i]->setVisible(false); connect(recentFileActions[i],SIGNAL(triggered()),this,SLOT(openRecentFile())); } saveAction = new QAction(tr("&Save"), this); saveAction->setIcon(QIcon(":/icon/save.png")); saveAction->setShortcut(QKeySequence::Save); saveAction->setStatusTip(tr("Save the current editting file")); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); saveAsAction = new QAction(tr("Save &As"),this); saveAsAction->setIcon(QIcon(":/icon/saveAs.png")); saveAsAction->setShortcut(QKeySequence::SaveAs); saveAsAction->setStatusTip(tr("Save the current file as another type of file")); connect(saveAsAction, SIGNAL(triggered()), this ,SLOT(saveAs())); closeAction = new QAction(tr("&Close"),this); closeAction->setShortcut(QKeySequence::Close); closeAction->setStatusTip(tr("Close this window")); connect(closeAction,SIGNAL(triggered()),this,SLOT(close())); exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcut(tr("Alt+F4")); exitAction->setStatusTip(tr("Exit the application")); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); cutAction = new QAction(tr("Cu&t"), this); cutAction->setIcon(QIcon(":/icon/cut.png")); cutAction->setShortcut(QKeySequence::Cut); cutAction->setStatusTip(tr("Cut the current selection's contents to the clipboard")); copyAction = new QAction(tr("&Copy"), this); copyAction->setIcon(QIcon(":/icon/copy.png")); copyAction->setShortcut(QKeySequence::Copy); copyAction->setStatusTip(tr("Copy the current selection's contents to the clipboard")); pasteAction = new QAction(tr("&Paste"), this); pasteAction->setIcon(QIcon(":/icon/paste.png")); pasteAction->setShortcut(QKeySequence::Paste); pasteAction->setStatusTip(tr("Paste the clipboard's contents into the current selection")); deleteAction = new QAction(tr("&Delete"), this); deleteAction->setIcon(QIcon(":/icon/delete.png")); deleteAction->setShortcut(QKeySequence::Delete); deleteAction->setStatusTip(tr("Delete the current selection's contents")); selectSequareAction = new QAction(tr("Se&lect"), this); selectSequareAction->setIcon(QIcon(":/icon/select.png")); selectSequareAction->setShortcut(tr("Ctrl+Q")); selectSequareAction->setStatusTip(tr("Select the choosen sequare area to the clipboard")); zoomInAction = new QAction(tr("&ZoomIn"), this); zoomInAction->setIcon(QIcon(":/icon/zoomIn.png")); zoomInAction->setShortcut(QKeySequence::ZoomIn); zoomInAction->setStatusTip(tr("Zoom in the picture")); zoomOutAction = new QAction(tr("Zoom&Out"), this); zoomOutAction->setIcon(QIcon(":/icon/zoomOut.png")); zoomOutAction->setShortcut(QKeySequence::ZoomOut); zoomOutAction->setStatusTip(tr("Zoom out the picture")); aboutAction = new QAction(tr("&About"), this); aboutAction->setStatusTip(tr("Show the application's About box")); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); aboutQtAction = new QAction(tr("About &Qt"), this); aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); }