#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#define PLUGINS_SUBFOLDER "/cvplugins/"
//#define PLUGINS_SUBFOLDER "/filter_plugins/"
#define LANGUAGES_SUBFOLDER "/languages/"
#define THEMES_SUBFOLDER "/themes/"
#define FILE_ON_DISK_DYNAMIC_PROPERTY "absolute_file_path"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
loadSettings(); // First thing's first, load settings
//加载插件菜单
populatePluginsMenu();
//加载多语言菜单
populateLanguagesMenu();
//加载主题菜单
populateThemesMenu();
ui->graphicsView->setScene(&scene);
scene.addItem(&originalPixmap);
scene.addItem(&processedPixmap);
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}
MainWindow::~MainWindow()
{
delete currentPlugin;
delete ui;
}
void MainWindow::loadSettings()
{
QSettings settings("Packt", "Computer_Vision", this);
currentThemeFile = settings.value("currentThemeFile", "").toString();
currentLanguageFile = settings.value("currentLanguageFile", "").toString();
currentPluginFile = settings.value("currentPluginFile", "").toString();
}
void MainWindow::saveSettings()
{
QSettings settings("Packt", "Computer_Vision", this);
settings.setValue("currentThemeFile", currentThemeFile);
settings.setValue("currentLanguageFile", currentLanguageFile);
settings.setValue("currentPluginFile", currentPluginFile);
}
void MainWindow::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
else
{
QMainWindow::changeEvent(event);
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
int result = QMessageBox::warning(this, tr("Exit"), tr("Are you sure you want to exit?"), QMessageBox::Yes, QMessageBox::No);
if(result == QMessageBox::Yes)
{
saveSettings();
event->accept();
}
else
{
event->ignore();
}
}
void MainWindow::populatePluginsMenu()
{
// Load all plugins and populate the menus
QDir pluginsDir(qApp->applicationDirPath() + PLUGINS_SUBFOLDER);
//QDir pluginsDir(qApp->applicationDirPath());
QFileInfoList pluginFiles = pluginsDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
qDebug() << "MainWindow::populatePluginsMenu=====================pluginFiles.size========" << pluginFiles.size();
foreach(QFileInfo pluginFile, pluginFiles)
{
if(QLibrary::isLibrary(pluginFile.absoluteFilePath()))
{
QPluginLoader pluginLoader(pluginFile.absoluteFilePath(), this);
if(CvPluginInterface *plugin = dynamic_cast<CvPluginInterface*>(pluginLoader.instance()))
{
QAction *pluginAction = ui->menu_Plugins->addAction(plugin->title());
pluginAction->setProperty(FILE_ON_DISK_DYNAMIC_PROPERTY, pluginFile.absoluteFilePath());
connect(pluginAction, SIGNAL(triggered(bool)), this, SLOT(onPluginActionTriggered(bool)));
if(currentPluginFile == pluginFile.absoluteFilePath())
{
pluginAction->trigger();
}
}
else
{
QMessageBox::warning(this, tr("Warning"),
QString(tr("Make sure %1 is a correct plugin for this application<br>"
"and it's not in use by some other application!")).arg(pluginFile.fileName()));
}
}
else
{
QMessageBox::warning(this, tr("Warning"),
QString(tr("Make sure only plugins exist in %1 folder.<br>"
"%2 is not a plugin."))
.arg(PLUGINS_SUBFOLDER)
.arg(pluginFile.fileName()));
}
}
if(ui->menu_Plugins->actions().count() <= 0)
{
QMessageBox::critical(this, tr("No Plugins"), QString(tr("This application cannot work without plugins!"
"<br>Make sure that %1 folder exists "
"in the same folder as the application<br>and that "
"there are some filter plugins inside it")).arg(PLUGINS_SUBFOLDER));
this->setEnabled(false);
}
}
void MainWindow::populateLanguagesMenu()
{
QMenu *languagesMenu = new QMenu(this);
// Add default (english) language
QAction *defaultLanguageAction = languagesMenu->addAction("English - US");
defaultLanguageAction->setProperty(FILE_ON_DISK_DYNAMIC_PROPERTY, "");
connect(defaultLanguageAction, SIGNAL(triggered(bool)), this, SLOT(onLanguageActionTriggered(bool)));
// Load all languages and populate the menus
QDir languagesDir(qApp->applicationDirPath() + LANGUAGES_SUBFOLDER);
QFileInfoList languageFiles = languagesDir.entryInfoList(QStringList() << "*.qm", QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
foreach(QFileInfo languageFile, languageFiles)
{
QAction *languageAction = languagesMenu->addAction(languageFile.baseName());
languageAction->setProperty(FILE_ON_DISK_DYNAMIC_PROPERTY, languageFile.absoluteFilePath());
connect(languageAction, SIGNAL(triggered(bool)), this, SLOT(onLanguageActionTriggered(bool)));
if(currentLanguageFile == languageFile.absoluteFilePath())
{
languageAction->trigger();
}
}
ui->actionLanguage->setMenu(languagesMenu);
}
void MainWindow::populateThemesMenu()
{
QMenu *themesMenu = new QMenu(this);
// Add default (native) theme
QAction *defaultThemeAction = themesMenu->addAction("Default");
defaultThemeAction->setProperty(FILE_ON_DISK_DYNAMIC_PROPERTY, "");
connect(defaultThemeAction, SIGNAL(triggered(bool)), this, SLOT(onThemeActionTriggered(bool)));
// Load all themes and populate the menus
QDir themesDir(qApp->applicationDirPath() + THEMES_SUBFOLDER);
QFileInfoList themeFiles = themesDir.entryInfoList(QStringList() << "*.thm", QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
foreach(QFileInfo themeFile, themeFiles)
{
QAction *themeAction = themesMenu->addAction(themeFile.baseName());
themeAction->setProperty(FILE_ON_DISK_DYNAMIC_PROPERTY, themeFile.absoluteFilePath());
connect(themeAction, SIGNAL(triggered(bool)), this, SLOT(onThemeActionTriggered(bool)));
if(currentThemeFile == themeFile.absoluteFilePath())
{
themeAction->trigger();
}
}
ui->actionTheme->setMenu(themesMenu);
}
void MainWindow::on_actionAboutQt_triggered()
{
qApp->aboutQt();
}
void MainWindow::on_actionExit_triggered()
{
close();
}
//加载插件
void MainWindow::onPluginActionTriggered(bool)
{
if(!currentPlugin.isNull())
{
delete currentPlugin;
delete currentPluginGui;
}
qDebug() << "MainWindow::onPluginActionTriggered====================currentPlugin========" << currentPlugin.isNull();
currentPluginFile = QObject::sender()->property(FILE_ON_DISK_DYNAMIC_PROPERTY).toString();
currentPlugin = new QPluginLoader(currentPluginFile, this);
currentPluginGui = new QWidget(this);
ui->pluginLayout->addWidget(currentPluginGui);
CvPluginInterface *currentPluginInstance = dynamic_cast<CvPluginInterface*>(currentPlugin->instance());
if(currentPluginInstance)
{
currentPluginInstance->setupUi(currentPluginGui);
connect(currentPlugin->instance(), SIGNAL(updateNeeded()), this, SLOT(onCurrentPluginUpdateNeeded()));
connect(currentPlugin->instance(), SIGNAL(infoMessage(QString)), this, SLOT(onCurrentPluginInfoMessage(QString)));
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
computer-vision计算机视图算法opencv相关 (410个子文件)
libFilter_Plugin.a 44KB
libTransform_Plugin.a 29KB
libSegmentation_Plugin.a 28KB
libCopyMakeBorder_Plugin.a 25KB
libColor_Plugin.a 23KB
libTemplate_Plugin.a 23KB
libFourier_Plugin.a 23KB
mainwindow.cpp 12KB
filter_plugin.cpp 11KB
transform_plugin.cpp 6KB
segmentation_plugin.cpp 3KB
fourier_plugin.cpp 2KB
color_plugin.cpp 2KB
copymakeborder_plugin.cpp 1KB
template_plugin.cpp 1KB
qenhancedgraphicsview.cpp 659B
main.cpp 206B
opencv_world480d.dll 93.53MB
opencv_world480.dll 60.23MB
libopencv_world.408.dylib 30.03MB
libopencv_world.408.dylib 30.03MB
core_c.h 129KB
msa_macros.h 82KB
types_c.h 72KB
kmeans_index.h 68KB
imgproc_c.h 51KB
dist.h 42KB
cvdef.h 37KB
constants_c.h 31KB
cv_cpu_helper.h 30KB
hierarchical_clustering_index.h 27KB
autotuned_index.h 21KB
kdtree_single_index.h 21KB
kdtree_index.h 21KB
lsh_table.h 19KB
types_c.h 18KB
lsh_index.h 16KB
result_set.h 15KB
index_testing.h 11KB
highgui_c.h 10KB
any.h 9KB
cv_cpu_dispatch.h 9KB
hdf5.h 7KB
heap.h 7KB
allocator.h 6KB
all_indices.h 6KB
composite_index.h 6KB
nn_index.h 6KB
saving.h 6KB
simplex_downhill.h 6KB
videoio_c.h 6KB
calib3d_c.h 5KB
cap_ios.h 5KB
interface.h 5KB
dynamic_bitset.h 5KB
defines.h 5KB
random.h 4KB
params.h 4KB
logger.h 4KB
linear_index.h 4KB
ground_truth.h 3KB
matrix.h 3KB
cvconfig.h 3KB
object_factory.h 3KB
sampling.h 3KB
ios.h 3KB
timer.h 3KB
filter_plugin.h 2KB
general.h 2KB
mainwindow.h 2KB
config.h 2KB
constants_c.h 2KB
transform_plugin.h 1KB
segmentation_plugin.h 1KB
interface.h 1KB
template_plugin.h 925B
copymakeborder_plugin.h 923B
color_plugin.h 846B
fourier_plugin.h 804B
macosx.h 751B
cvplugininterface.h 625B
interface.h 584B
qenhancedgraphicsview.h 581B
constants_c.h 478B
constants_c.h 412B
copymakeborder_plugin_global.h 324B
segmentation_plugin_global.h 312B
transform_plugin_global.h 294B
template_plugin_global.h 288B
fourier_plugin_global.h 282B
filter_plugin_global.h 276B
color_plugin_global.h 270B
dummy.h 213B
imgcodecs_c.h 146B
intrin_rvv_010_compat_non-policy.hpp 1.74MB
imgproc.hpp 246KB
calib3d.hpp 221KB
color_detail.hpp 221KB
mat.hpp 165KB
intrin_avx512.hpp 160KB
共 410 条
- 1
- 2
- 3
- 4
- 5
资源评论
班公湖里洗过脚
- 粉丝: 582
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功