extern int _qemu_argc;
extern char **_qemu_argv;
+#define TABLE_BORDER_SIZE 2
+#define TAB_BORDER_SIZE 4
+#define DIALOG_HORIZ_SPACE 20
+#define DIALOG_VERTIC_SPACE 60
+#define DIALOG_MIN_WIDTH 200
+#define DIALOG_MIN_HEIGHT 200
+#define DIALOG_DEF_WIDTH 320
+#define DIALOG_DEF_HEIGHT 480
+
DetailedInfoDialog::DetailedInfoDialog(QWidget *parent) :
- QDialog(parent, Qt::Tool | Qt::WindowTitleHint |
- Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
+ QDialog(parent)
{
- QStringList imagePathList = getImagePathList();
- MainWindow *win = ((MainWindow *)parent);
+ win = ((MainWindow *)parent);
keyboardShortcut = win->getKeyboardShortcut();
setWindowTitle(DETAILED_INFO_TITLE);
+ setMinimumWidth(DIALOG_MIN_WIDTH);
+ setMinimumHeight(DIALOG_MIN_HEIGHT);
baseLayout = new QVBoxLayout(this);
baseLayout->setMargin(10);
baseLayout->setSpacing(10);
/* upside */
- upsideLayout = new QHBoxLayout(this);
+ upsideLayout = new QHBoxLayout();
upsideLayout->setMargin(0);
upsideLayout->setSpacing(0);
/* tab */
tabWidget = new QTabWidget(this);
- QWidget *vmInfo = new QWidget;
- QWidget *shortcutInfo = new QWidget;
+
+ /* VM information table */
+ QTableWidget *vmInfo = createVmInfoTable();
tabWidget->addTab(vmInfo, tr(DETAILED_INFO_VMTAB_TITLE));
+
+ /* shortcut info table */
+ QTableWidget *shortcutInfo = createShortcutInfoTable();
tabWidget->addTab(shortcutInfo, tr(DETAILED_INFO_SHORTCUTTAB_TITLE));
- connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotSetMaximumSize(int)));
+ upsideLayout->addWidget(tabWidget);
- /* VM information table */
- vmInfoTable = new QTableWidget(vmInfo);
- vmInfoTable->setColumnCount(2);
- vmInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
- vmInfoTable->setAlternatingRowColors(true);
- vmInfoTable->verticalHeader()->hide();
+ baseLayout->addLayout(upsideLayout);
+
+ /* downside */
+ downsideLayout = new QHBoxLayout();
+ downsideLayout->setAlignment(Qt::AlignRight);
+ downsideLayout->setMargin(0);
- QStringList header;
- header << DETAILED_INFO_VMTAB_HEADER1 << DETAILED_INFO_VMTAB_HEADER2;
- vmInfoTable->setHorizontalHeaderLabels(header);
+ QPushButton *okBtn = new QPushButton("OK", this);
+ connect(okBtn, SIGNAL(clicked()), this, SLOT(close()));
+ downsideLayout->addWidget(okBtn);
- /* shortcut info table */
- shortcutInfoTable = new QTableWidget(shortcutInfo);
- shortcutInfoTable->setColumnCount(2);
- shortcutInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
- shortcutInfoTable->setAlternatingRowColors(true);
- shortcutInfoTable->verticalHeader()->hide();
+ baseLayout->addLayout(downsideLayout);
+
+ resize(DIALOG_DEF_WIDTH, DIALOG_DEF_HEIGHT);
+}
+
+QTableWidget *DetailedInfoDialog::createVmInfoTable()
+{
+ vmInfoTable = new QTableWidget();
+
+ /* horizontal headers */
+ QStringList headers;
+ headers << DETAILED_INFO_VMTAB_HEADER1 << DETAILED_INFO_VMTAB_HEADER2;
+
+ vmInfoTable->setColumnCount(headers.count());
+ vmInfoTable->setHorizontalHeaderLabels(headers);
+ vmInfoTable->horizontalHeader()->setStretchLastSection(true);
+ vmInfoTable->verticalHeader()->hide();
- header.clear();
- header << DETAILED_INFO_SHORTCUTTAB_HEADER1 << DETAILED_INFO_SHORTCUTTAB_HEADER2;
- shortcutInfoTable->setHorizontalHeaderLabels(header);
+ vmInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ vmInfoTable->setAlternatingRowColors(true);
- /* table items */
+ /* insert table items */
int index = 0;
- setDataTable(vmInfoTable, DETAILED_INFO_VM_NAME,
+ insertTableRow(vmInfoTable, DETAILED_INFO_VM_NAME,
win->uiInfo->vmName, index++);
- setDataTable(vmInfoTable, DETAILED_INFO_SKIN_NAME,
+ insertTableRow(vmInfoTable, DETAILED_INFO_SKIN_NAME,
win->uiInfo->skinName, index++);
- setDataTable(vmInfoTable, DETAILED_INFO_CPU, "x86", index++);
+ insertTableRow(vmInfoTable, DETAILED_INFO_CPU, "x86", index++);
- setDataTable(vmInfoTable, DETAILED_INFO_RAM_SIZE,
+ insertTableRow(vmInfoTable, DETAILED_INFO_RAM_SIZE,
QString::number(get_ram_size() >> 20) + " MiB", index++);
- setDataTable(vmInfoTable, DETAILED_INFO_DPY_RESOLUTION,
+
+ insertTableRow(vmInfoTable, DETAILED_INFO_DPY_RESOLUTION,
QString::number(win->uiInfo->resolution.width()) + "x" +
QString::number(win->uiInfo->resolution.height()), index++);
- setDataTable(vmInfoTable, DETAILED_INFO_DPY_DENSITY,
+ insertTableRow(vmInfoTable, DETAILED_INFO_DPY_DENSITY,
QString::number(get_display_pixel_density()), index++);
QString sharingPath(get_emul_file_sharing_path());
- setDataTable(vmInfoTable, DETAILED_INFO_HDS_PATH,
+ insertTableRow(vmInfoTable, DETAILED_INFO_HDS_PATH,
(sharingPath.isEmpty()) ? GENERIC_TEXT_NONE : sharingPath, index++);
- setDataTable(vmInfoTable, DETAILED_INFO_CPU_VT,
+ insertTableRow(vmInfoTable, DETAILED_INFO_CPU_VT,
(get_emul_cpu_accel()) ? GENERIC_TEXT_ENABLED : GENERIC_TEXT_DISABLED, index++);
- setDataTable(vmInfoTable, DETAILED_INFO_GPU_VT,
+ insertTableRow(vmInfoTable, DETAILED_INFO_GPU_VT,
(is_gpu_accel_enabled()) ? GENERIC_TEXT_ENABLED : GENERIC_TEXT_DISABLED, index++);
+ QStringList imagePathList = getImagePathList();
for (int i = 0; i < imagePathList.size(); i++) {
- setDataTable(vmInfoTable, QString(DETAILED_INFO_IMAGE_PATH) + " " +
+ insertTableRow(vmInfoTable, QString(DETAILED_INFO_IMAGE_PATH) + " " +
QString::number(i + 1), imagePathList[i], index++);
item->setToolTip(imagePathList[i]);
}
- setDataTable(vmInfoTable, DETAILED_INFO_LOG_PATH, get_log_path(), index++);
+ insertTableRow(vmInfoTable, DETAILED_INFO_LOG_PATH, get_log_path(), index++);
item->setToolTip(get_log_path());
#if 0
- setDataTable(vmInfoTable, DETAILED_INFO_TELNET_PORT,
+ insertTableRow(vmInfoTable, DETAILED_INFO_TELNET_PORT,
QString::number(get_emul_serial_port()), index++);
#endif
/* add double click event listener */
connect(vmInfoTable, SIGNAL(cellDoubleClicked(int, int)),
- this, SLOT(slotDoubleClicked(int, int)));
-
- int tableHeight = vmInfoTable->horizontalHeader()->height();
- for (int i = 0; i < vmInfoTable->rowCount(); i++) {
- tableHeight += vmInfoTable->rowHeight(i);
- }
-
- setMinimumWidth(DIALOG_MIN_WIDTH);
- setMinimumHeight(DIALOG_MIN_HEIGHT);
- slotSetMaximumSize(tabWidget->currentIndex());
+ this, SLOT(slotCellOpen(int, int)));
- upsideLayout->addWidget(tabWidget);
+ return vmInfoTable;
+}
- baseLayout->addLayout(upsideLayout);
+QTableWidget *DetailedInfoDialog::createShortcutInfoTable()
+{
+ shortcutInfoTable = new QTableWidget();
- /* downside */
- downsideLayout = new QHBoxLayout(this);
- downsideLayout->setAlignment(Qt::AlignRight);
- downsideLayout->setMargin(0);
+ /* horizontal headers */
+ QStringList headers;
+ headers << DETAILED_INFO_SHORTCUTTAB_HEADER1 << DETAILED_INFO_SHORTCUTTAB_HEADER2;
- okBtn = new QPushButton("OK", this);
- connect(okBtn, SIGNAL(clicked()), this, SLOT(close()));
- downsideLayout->addWidget(okBtn);
+ shortcutInfoTable->setColumnCount(headers.count());
+ shortcutInfoTable->setHorizontalHeaderLabels(headers);
+ shortcutInfoTable->horizontalHeader()->setStretchLastSection(true);
+ shortcutInfoTable->verticalHeader()->hide();
- baseLayout->addLayout(downsideLayout);
+ shortcutInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ shortcutInfoTable->setAlternatingRowColors(true);
- resize(DIALOG_DEF_WIDTH, DIALOG_DEF_HEIGHT);
+ return shortcutInfoTable;
}
-void DetailedInfoDialog::slotSetMaximumSize(int tab)
+void DetailedInfoDialog::updateShortcutTableItems()
{
- QTableWidget *table = NULL;
- int tRow = 0;
- int tHeight = 0;
- int tWidth = 0;
-
- switch (tab) {
- case 0: /* vmInfoTab */
- table = vmInfoTable;
- break;
- case 1: /* shortcutInfoTab */
- table = shortcutInfoTable;
- break;
- default:
- qWarning() << "unimplemented tab: " << tab;
- return;
- }
-
- table->resizeColumnsToContents();
-
- /* width */
- tWidth = table->columnWidth(0) + table->columnWidth(1);
- tWidth = (tWidth < DIALOG_DEF_WIDTH) ? DIALOG_DEF_WIDTH : tWidth;
-
- setMaximumWidth(tWidth + TABLE_BORDER_SIZE +
- TAB_BORDER_SIZE +
- DIALOG_HORIZ_SPACE);
-
- /* height */
- tHeight = table->horizontalHeader()->height();
- for (tRow = 0; tRow < table->rowCount(); tRow++) {
- tHeight += table->rowHeight(tRow);
- }
+ qDebug() << "clear" << shortcutInfoTable->rowCount() << "shortcut items";
+ removeTableRows(shortcutInfoTable, 0, shortcutInfoTable->rowCount());
- setMaximumHeight(tHeight + TABLE_BORDER_SIZE +
- tabWidget->tabBar()->sizeHint().height() +
- DIALOG_VERTIC_SPACE);
+ /* insert shortcut info */
+ setShortcutInfoTable(keyboardShortcut->getPopupMenuShortcutMap(),
+ keyboardShortcut->getPopupMenuShortcutList());
+ setShortcutInfoTable(keyboardShortcut->getHwKeyShortcutMap(),
+ keyboardShortcut->getHwKeyShortcutList());
+ setShortcutInfoTable(keyboardShortcut->getControllerShortcutMap(),
+ keyboardShortcut->getControllerShortcutList());
- table->horizontalHeader()->setStretchLastSection(true);
+ qDebug() << shortcutInfoTable->rowCount() << "shortcut items have been inserted";
}
void DetailedInfoDialog::setShortcutInfoTable(
#ifdef CONFIG_DARWIN
QString value = mapIter.value();
value.replace("Ctrl", "Cmd");
- setDataTable(shortcutInfoTable, mapIter.key(), value, row++);
+ insertTableRow(shortcutInfoTable, mapIter.key(), value, row++);
#else
- setDataTable(shortcutInfoTable, mapIter.key(), mapIter.value(), row++);
+ insertTableRow(shortcutInfoTable, mapIter.key(), mapIter.value(), row++);
#endif
break;
}
}
}
-void DetailedInfoDialog::setDataTable(
- QTableWidget* table, QString key, QString value, int index)
+/* override */
+void DetailedInfoDialog::showEvent(QShowEvent *event)
+{
+ updateShortcutTableItems();
+
+ if ((windowState() & Qt::WindowMaximized) == 0) {
+ tabWidget->setCurrentIndex(0);
+ resizeTableToContents(vmInfoTable);
+ }
+
+ move(win->geometry().center().x() - (geometry().size().width() / 2),
+ win->geometry().center().y() - (geometry().size().height() / 2));
+
+ QDialog::showEvent(event);
+}
+
+/* override */
+void DetailedInfoDialog::resizeEvent(QResizeEvent *event)
+{
+ /* do nothing */
+
+ QDialog::resizeEvent(event);
+}
+
+void DetailedInfoDialog::resizeTableToContents(QTableWidget *table)
+{
+ /* width */
+ int tWidth = qMin(table->columnWidth(0) + table->columnWidth(1), DIALOG_DEF_WIDTH);
+ tWidth += TABLE_BORDER_SIZE + TAB_BORDER_SIZE + DIALOG_HORIZ_SPACE;
+
+ /* height */
+ int tHeight = table->horizontalHeader()->height();
+ for (int tRow = 0; tRow < table->rowCount(); tRow++) {
+ tHeight += table->rowHeight(tRow);
+ }
+ tHeight += TABLE_BORDER_SIZE +
+ tabWidget->tabBar()->sizeHint().height() + DIALOG_VERTIC_SPACE;
+
+ resize(tWidth, tHeight);
+
+ shortcutInfoTable->resizeColumnsToContents();
+ vmInfoTable->resizeColumnsToContents();
+}
+
+void DetailedInfoDialog::insertTableRow(
+ QTableWidget *table, QString key, QString value, int index)
{
table->insertRow(index);
item = new QTableWidgetItem(key);
table->setItem(index, 1, item);
}
-void DetailedInfoDialog::resizeEvent(QResizeEvent* event)
-{
- int tWidth = 0, tHeight = 0;
- tWidth = event->size().width() - TAB_BORDER_SIZE - DIALOG_HORIZ_SPACE;
- tHeight = event->size().height() - tabWidget->tabBar()->sizeHint().height() -
- DIALOG_VERTIC_SPACE;
-
- vmInfoTable->resize(tWidth, tHeight);
- shortcutInfoTable->resize(tWidth, tHeight);
-}
-
-void DetailedInfoDialog::removeDataTable(QTableWidget* table, int startIndex, int lastIndex)
+void DetailedInfoDialog::removeTableRows(
+ QTableWidget *table, int startIndex, int lastIndex)
{
- for (int cnt = startIndex; cnt < lastIndex; cnt++) {
+ for (int index = startIndex; index < lastIndex; index++) {
table->removeRow(startIndex);
}
}
return imagePathList;
}
-void DetailedInfoDialog::slotDoubleClicked(int nRow, int nCol)
+void DetailedInfoDialog::slotCellOpen(int nRow, int nCol)
{
- QTableWidgetItem *item;
- QString string;
-
- /* Feature side double click event is occured, ignore it */
- if (nCol == 0)
+ if (nCol <= 0 || nRow >= vmInfoTable->rowCount()) {
return;
+ }
+
+ QTableWidgetItem *item = vmInfoTable->item(nRow, 0);
+ qDebug() << item->text() << "item was double clicked";
- item = vmInfoTable->item(nRow, 0);
if (item->text().compare(DETAILED_INFO_HDS_PATH, Qt::CaseInsensitive) == 0 ||
- item->text().startsWith(DETAILED_INFO_IMAGE_PATH) == true ||
- item->text().compare(DETAILED_INFO_LOG_PATH, Qt::CaseInsensitive) == 0) {
- /* get path name */
+ item->text().compare(DETAILED_INFO_LOG_PATH, Qt::CaseInsensitive) == 0 ||
+ item->text().startsWith(DETAILED_INFO_IMAGE_PATH) == true) {
+ /* get path item */
item = vmInfoTable->item(nRow, nCol);
- if (item->text().compare("None", Qt::CaseInsensitive) == 0 ||
- item->text().compare("", Qt::CaseInsensitive) == 0) {
+
+ if (item->text().compare(GENERIC_TEXT_NONE, Qt::CaseInsensitive) == 0 ||
+ item->text().isEmpty() == true) {
/* ignore this event */
return;
}
return;
}
- if (QFileInfo(item->text()).isDir() == true) {
- /* path name is a directory name */
- QDesktopServices::openUrl(QUrl("file:///" + item->text(), QUrl::TolerantMode));
- } else if (QFileInfo(item->text()).isFile() == true) {
- /* path name is a file name */
- QDesktopServices::openUrl(QUrl(
- "file:///" + QFileInfo(item->text()).absolutePath(), QUrl::TolerantMode));
+ QFileInfo pathInfo(item->text());
+ if (pathInfo.isDir() == true) {
+ /* directory path */
+ QDesktopServices::openUrl(
+ QUrl("file:///" + item->text(), QUrl::TolerantMode));
+ } else if (pathInfo.isFile() == true) {
+ /* file path */
+ QDesktopServices::openUrl(
+ QUrl("file:///" + pathInfo.absolutePath(), QUrl::TolerantMode));
} else {
- qWarning("wrong path name");
+ qWarning() << "invalid path info:" << item->text();
}
return;
}
-void DetailedInfoDialog::showEvent(QShowEvent *event)
-{
- Q_UNUSED(event)
-
- QWidget *win = parentWidget();
- move(win->geometry().center().x() - (geometry().size().width() / 2),
- win->geometry().center().y() - (geometry().size().height() / 2));
-
- /* insert shortcut info */
- removeDataTable(shortcutInfoTable, 0, shortcutInfoTable->rowCount());
- setShortcutInfoTable(keyboardShortcut->getPopupMenuShortcutMap(),
- keyboardShortcut->getPopupMenuShortcutList());
- setShortcutInfoTable(keyboardShortcut->getHwKeyShortcutMap(),
- keyboardShortcut->getHwKeyShortcutList());
- setShortcutInfoTable(keyboardShortcut->getControllerShortcutMap(),
- keyboardShortcut->getControllerShortcutList());
-
- vmInfoTable->horizontalHeader()->setStretchLastSection(true);
- shortcutInfoTable->horizontalHeader()->setStretchLastSection(true);
-}
-
-QTableWidget *DetailedInfoDialog::getShortcutInfoTable()
-{
- return shortcutInfoTable;
-}
-
DetailedInfoDialog::~DetailedInfoDialog()
{
qDebug("destroy detailed info dialog");
-
- for (int i = 0; i < vmInfoTable->rowCount(); i++) {
- for (int j = 0; j < vmInfoTable->columnCount(); j++) {
- delete vmInfoTable->item(i, j);
- }
- }
-
- for (int i = 0; i < shortcutInfoTable->rowCount(); i++) {
- for (int j = 0; j < shortcutInfoTable->columnCount(); j++) {
- delete shortcutInfoTable->item(i, j);
- }
- }
}