From: Masayuki Satoh Date: Sun, 24 Aug 2014 05:22:10 +0000 (+0900) Subject: Ver0.10pre X-Git-Url: http://git.osdn.net/view?p=gefu%2FGefu.git;a=commitdiff_plain;h=255a60892a4df855783726f2c9aca8c60366d3f5 Ver0.10pre --- diff --git a/README.md b/README.md index 35f50a8..dab55e0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,17 @@ Gefu is an Experimental File Utility. - 簡易FTPクライアント - SNS連携(タイムライン表示とか) ← ファイラーの機能か? +#### 2014/08/24 Ver0.10 +- 環境設定ダイアログの変更 + - コントロールの活性・非活性切り替えを修正。 + - フォント選択をダイアログ使用に変更。 + - ファイルビューのサンプル表示を実際の形に変更。 + - テキストビューアの設定を追加。 +- 安直な文字コード判別を実装 + - BOMがあれば、それに従う。 + - 先頭1KB中に文字コードを示す文字列("shift_jis"等)があれば、その文字コードに変換する。 + - バイト単位で調べて推測(http://dobon.net/vb/dotnet/string/detectcode.html よりコードを拝借) + #### 2014/08/24 Ver0.09 公開 - 左右矢印キーに機能割り当て - 左ペインで左矢印/右ペインで右矢印 → 親フォルダに移動 diff --git a/colorsamplemodel.cpp b/colorsamplemodel.cpp index 7a0fb40..7590448 100644 --- a/colorsamplemodel.cpp +++ b/colorsamplemodel.cpp @@ -15,13 +15,13 @@ void ColorSampleModel::setFont(const QFont &font) int ColorSampleModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); - return 3; + return 5; } int ColorSampleModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); - return 2; + return 3; } QVariant ColorSampleModel::data(const QModelIndex &index, int role) const @@ -30,10 +30,12 @@ QVariant ColorSampleModel::data(const QModelIndex &index, int role) const return QVariant(); } - const QString strText[3][2] = { - { tr("通常"), tr("システム") }, - { tr("マーク"), tr("隠し属性") }, - { tr(""), tr("読取専用") } + const QString strText[5][3] = { + { tr("通常"), tr(""), tr("12/34/56 78:90") }, + { tr("マーク"), tr("123B"), tr("12/34/56 78:90") }, + { tr("システム"), tr("456KB"), tr("12/34/56 78:90") }, + { tr("隠し属性"), tr("789MB"), tr("12/34/56 78:90") }, + { tr("読取専用"), tr("10.2GB"), tr("12/34/56 78:90") } }; switch (role) { @@ -45,43 +47,23 @@ QVariant ColorSampleModel::data(const QModelIndex &index, int role) const break; case Qt::BackgroundRole: - switch (index.column()) { - case 0: - switch (index.row()) { - case 0: return QBrush(m_colorMap->value("clrBgNormal")); - case 1: return QBrush(m_colorMap->value("clrBgMark")); - } - break; - - case 1: - switch (index.row()) { - case 0: - case 1: - case 2: - return QBrush(m_colorMap->value("clrBgNormal")); - } - break; + if (index.row() == 1) { + return QBrush(m_colorMap->value("clrBgMark")); + } + else { + return QBrush(m_colorMap->value("clrBgNormal")); } break; case Qt::ForegroundRole: - switch (index.column()) { - case 0: - switch (index.row()) { - case 0: return QBrush(m_colorMap->value("clrFgNormal")); - case 1: return QBrush(m_colorMap->value("clrFgMark")); - } - break; - - case 1: - switch (index.row()) { - case 0: return QBrush(m_colorMap->value("clrFgSystem")); - case 1: return QBrush(m_colorMap->value("clrFgHidden")); - case 2: return QBrush(m_colorMap->value("clrFgReadonly")); - } - break; - } + switch (index.row()) { + case 0: return QBrush(m_colorMap->value("clrFgNormal")); + case 1: return QBrush(m_colorMap->value("clrFgMark")); + case 2: return QBrush(m_colorMap->value("clrFgSystem")); + case 3: return QBrush(m_colorMap->value("clrFgHidden")); + case 4: return QBrush(m_colorMap->value("clrFgReadonly")); break; + } } return QVariant(); diff --git a/common.h b/common.h index 51f1c12..7543459 100644 --- a/common.h +++ b/common.h @@ -7,8 +7,9 @@ typedef QMap StringMap; class MainWindow; extern MainWindow* getMainWnd(); extern QString FilesizeToString(quint64 size); +extern QString ViewerIgnoreExt(); -#define VERSION_VALUE 0.09 +#define VERSION_VALUE 0.10 #define slash QString("/") #define QQ(x) ("\"" + QString(x) + "\"") @@ -50,6 +51,12 @@ extern QString FilesizeToString(quint64 size); #define IniKey_EditorOption "Editor/Option" #define IniKey_TerminalPath "Terminal/Path" #define IniKey_TerminalOption "Terminal/Option" +#define IniKey_ViewerFont "Viewer/Font" +#define IniKey_ViewerColorBg "Viewer/ColorBg" +#define IniKey_ViewerColorFg "Viewer/ColorFg" +#define IniKey_ViewerInherit "Viewer/Inherit" +#define IniKey_ViewerForceOpen "Viewer/ForceOpen" +#define IniKey_ViewerIgnoreExt "Viewer/IgnoreExt" #define IniKey_WindowGeometry "Window/Geometry" #define iniKey_WindowState "Window/State" // 以下は[Left/Right]セクションのキー diff --git a/filetableview.cpp b/filetableview.cpp index f9f08e1..2b88e16 100644 --- a/filetableview.cpp +++ b/filetableview.cpp @@ -195,6 +195,16 @@ void FileTableView::openItem() setRootIndex(index); } else { + QSettings settings; + if (!settings.value(IniKey_ViewerForceOpen).toBool()) { + QStringList list = settings.value(IniKey_ViewerIgnoreExt).toString().split(","); + foreach (const QString &ext, list) { + if (ext.toLower() == m->fileInfo(index).suffix().toLower()) { + openUrl(index); + return; + } + } + } emit openRequested(m->fileInfo(index)); } } diff --git a/main.cpp b/main.cpp index c3282c7..e8d9796 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ int main(int argc, char *argv[]) #else a.setWindowIcon(QIcon(":/images/Gefu.png")); #endif + QSettings::setDefaultFormat(QSettings::IniFormat); QSettings settings; if (settings.value(IniKey_ResetOnBoot, false).toBool()) { @@ -33,12 +34,12 @@ int main(int argc, char *argv[]) //>>>>> 起動と終了 if (settings.value(IniKey_ConfirmExit, "").toString().isEmpty()) settings.setValue(IniKey_ConfirmExit, true); - if (settings.value(IniKey_BootSizeSpec, "").toString().isEmpty()) { + if (settings.value(IniKey_BootSizeAbs, "").toString().isEmpty()) { settings.setValue(IniKey_BootSizeSpec, "sizeRelative"); settings.setValue(IniKey_BootSizeAbs, QSize(800,600)); settings.setValue(IniKey_BootSizeRel, QSize(75,75)); } - if (settings.value(IniKey_BootPosSpec, "").toString().isEmpty()) { + if (settings.value(IniKey_BootPosAbs, "").toString().isEmpty()) { settings.setValue(IniKey_BootPosSpec, "posCenter"); settings.setValue(IniKey_BootPosAbs, QPoint(0, 0)); settings.setValue(IniKey_BootPosRel, QPoint(0, 0)); @@ -101,6 +102,16 @@ int main(int argc, char *argv[]) settings.setValue(IniKey_TerminalOption, "-c cd " + QQ("$D")); #endif } + //>>>>> テキストビューア + if (settings.value(IniKey_ViewerFont, "").toString().isEmpty()) { + settings.setValue(IniKey_ViewerColorBg, QPalette().base().color()); + settings.setValue(IniKey_ViewerColorFg, QPalette().text().color()); + settings.setValue(IniKey_ViewerFont, a.font()); + settings.setValue(IniKey_ViewerForceOpen, false); + settings.setValue(IniKey_ViewerInherit, true); + settings.setValue(IniKey_ViewerIgnoreExt, ViewerIgnoreExt()); + } + //>>>>> 隠しファイルの表示 if (settings.value(IniKey_ShowHidden, "").toString().isEmpty()) settings.setValue(IniKey_ShowHidden, false); @@ -133,3 +144,29 @@ int main(int argc, char *argv[]) return a.exec(); } + +QString ViewerIgnoreExt() +{ + QStringList list; + // 画像系 + list << "gif" << "jpg" << "jpeg" << "png" << "bmp" << "ico" << "ai"; + list << "psd" << "xcf" << "tif" << "tiff" << "wmf"; + // 音・動画系 + list << "wav" << "mp3" << "ogg" << "midi" << "mid" << "aif" << "aiff"; + list << "mov" << "mpg" << "mpeg" << "wma" << "wmv" << "asf" << "avi"; + list << "flac" << "mkv"; + // 実行ファイル系 + list << "exe" << "com" << "lib" << "dll" << "msi" << "scr" << "sys"; + list << "o" << "obj" << "ocx" << "a" << "so" << "app"; + // アーカイブ系 + list << "lzh" << "zip" << "cab" << "tar" << "rar" << "gz" << "tgz"; + list << "bz2" << "xz" << "jar" << "7z"; + // ドキュメント系 + list << "pdf" << "doc" << "docx" << "xls" << "xlsx" << "ppt" << "pptx"; + // フォント + list << "ttf" << "ttc"; + + list.sort(); + + return list.join(","); +} diff --git a/mainwindow.cpp b/mainwindow.cpp index f4ff2eb..8febeeb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -338,6 +338,7 @@ void MainWindow::closeEvent(QCloseEvent *event) msgBox.setCheckBox(checkBox); msgBox.setText(tr("終了しますか?")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setIcon(QMessageBox::Question); if (msgBox.exec() == QMessageBox::No) { event->ignore(); diff --git a/preferencedialog.cpp b/preferencedialog.cpp index e6307d4..b0e2fc6 100644 --- a/preferencedialog.cpp +++ b/preferencedialog.cpp @@ -10,6 +10,7 @@ #include #include #include +#include PreferenceDialog::PreferenceDialog(QWidget *parent) : QDialog(parent), @@ -21,11 +22,20 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : ui->setupUi(this); ui->tabWidget->setCurrentIndex(0); + // アドレスボックスの外観サンプル ui->sampleEdit->setText(QDir::homePath()); + // ファイルビューの外観サンプル ui->sampleTable->setModel(&m_model); - ui->sampleTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - ui->sampleTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + QHeaderView *header; + header = ui->sampleTable->horizontalHeader(); + header->setSectionResizeMode(0, QHeaderView::Stretch); + header->setSectionResizeMode(1, QHeaderView::ResizeToContents); + header->setSectionResizeMode(2, QHeaderView::ResizeToContents); + header = ui->sampleTable->verticalHeader(); + header->setDefaultSectionSize(header->defaultSectionSize() * 0.75); + + // シグナル&スロット connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); @@ -44,19 +54,22 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor())); connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor())); - connect(ui->boxFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont())); - connect(ui->boxFontBold, SIGNAL(clicked()), this, SLOT(changeFont())); - connect(ui->boxFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont())); - - connect(ui->viewFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont())); - connect(ui->viewFontBold, SIGNAL(clicked()), this, SLOT(changeFont())); - connect(ui->viewFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont())); + connect(ui->chooseBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont())); + connect(ui->chooseViewFont, SIGNAL(clicked()), this, SLOT(chooseFont())); connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance())); connect(ui->exportAppearance, SIGNAL(clicked()), this, SLOT(exportAppearance())); connect(ui->termBrowse, SIGNAL(clicked()), this, SLOT(browseApp())); connect(ui->editorBrowse, SIGNAL(clicked()), this, SLOT(browseApp())); + connect(ui->chooseViewerFont, SIGNAL(clicked()), this, SLOT(chooseFont())); + connect(ui->viewerClrBg, SIGNAL(clicked()), this, SLOT(selectViewerColor())); + connect(ui->viewerClrFg, SIGNAL(clicked()), this, SLOT(selectViewerColor())); + connect(ui->viewerInherit, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->enableViewerIgnoreExt, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->defaultIgnoreExt, SIGNAL(clicked()), this, SLOT(setIgnoreExtDefault())); + + // 現在の設定で各コントロールを初期化する QSettings settings; QString strValue; QSize size; @@ -67,18 +80,16 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : // 終了時の確認ダイアログ ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit).toBool()); // 起動時のサイズ + ui->bootSize->setChecked(true); strValue = settings.value(IniKey_BootSizeSpec).toString(); + radioBtn = findChild(strValue); + if (radioBtn == NULL) { + radioBtn = ui->sizeRelative; + } + radioBtn->setChecked(true); if (strValue.isEmpty()) { ui->bootSize->setChecked(false); } - else { - ui->bootSize->setChecked(true); - radioBtn = findChild(strValue); - if (radioBtn == NULL) { - radioBtn = ui->sizeLast; - } - radioBtn->setChecked(true); - } size = settings.value(IniKey_BootSizeAbs).toSize(); ui->absoluteWidth->setValue(size.width()); ui->absoluteHeight->setValue(size.height()); @@ -86,18 +97,16 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : ui->relativeWidth->setValue(size.width()); ui->relativeHeight->setValue(size.height()); // 起動時の位置 + ui->bootPos->setChecked(true); strValue = settings.value(IniKey_BootPosSpec).toString(); + radioBtn = findChild(strValue); + if (radioBtn == NULL) { + radioBtn = ui->posCenter; + } + radioBtn->setChecked(true); if (strValue.isEmpty()) { ui->bootPos->setChecked(false); } - else { - ui->bootPos->setChecked(true); - radioBtn = findChild(strValue); - if (radioBtn == NULL) { - radioBtn = ui->posLast; - } - radioBtn->setChecked(true); - } point = settings.value(IniKey_BootPosAbs).toPoint(); ui->absoluteLeft->setValue(point.x()); ui->absoluteTop->setValue(point.y()); @@ -107,8 +116,8 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : // 起動時の設定削除 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot).toBool()); - //>>>>> 色とフォント - loadAppearance(settings); + //>>>>> 色とフォント、テキストビューア + loadAppearance(settings, false); //>>>>> ファイル操作 // 確認ダイアログの表示 @@ -141,6 +150,11 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : // ターミナル ui->termOpt->setText(settings.value(IniKey_TerminalOption).toString()); ui->termPath->setText(settings.value(IniKey_TerminalPath).toString()); + + //>>>>> テキストビューア + ui->enableViewerIgnoreExt->setChecked(true); + ui->enableViewerIgnoreExt->setChecked(!settings.value(IniKey_ViewerForceOpen).toBool()); + ui->viewerIgnoreExt->setPlainText(settings.value(IniKey_ViewerIgnoreExt).toString()); } PreferenceDialog::~PreferenceDialog() @@ -166,7 +180,7 @@ void PreferenceDialog::saveAppearance(QSettings &settings) settings.setValue(IniKey_ViewFont, m_model.font()); } -void PreferenceDialog::loadAppearance(QSettings &settings) +void PreferenceDialog::loadAppearance(QSettings &settings, bool import) { QPalette palette; QColor color; @@ -182,12 +196,11 @@ void PreferenceDialog::loadAppearance(QSettings &settings) palette.setColor(QPalette::Text, color); // フォント font = settings.value(IniKey_BoxFont).value(); - ui->boxFont->setCurrentText(font.family()); - ui->boxFontBold->setChecked(font.bold()); - ui->boxFontSize->setValue(font.pointSize()); + ui->boxFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize())); // サンプル表示 ui->sampleEdit->setPalette(palette); ui->sampleEdit->setFont(font); + //>>>> ファイルビュー // 背景色 color = settings.value(IniKey_ViewColorBgMark).value(); @@ -207,35 +220,69 @@ void PreferenceDialog::loadAppearance(QSettings &settings) m_colorMap["clrFgSystem"] = color; // フォント font = settings.value(IniKey_ViewFont).value(); - ui->viewFont->setCurrentText(font.family()); - ui->viewFontBold->setChecked(font.bold()); - ui->viewFontSize->setValue(font.pointSize()); + ui->viewFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize())); // サンプル表示 m_model.setFont(font); m_model.update(); + //>>>> テキストビューア + // 文字色と背景色 + if (settings.value(IniKey_ViewerInherit).toBool()) { + ui->viewerInherit->setChecked(true); + color = settings.value(IniKey_ViewColorBgNormal).value(); + palette.setColor(QPalette::Base, color); + color = settings.value(IniKey_ViewColorFgNormal).value(); + palette.setColor(QPalette::Text, color); + } + else if (!import){ + ui->viewerInherit->setChecked(false); + color = settings.value(IniKey_ViewerColorBg).value(); + palette.setColor(QPalette::Base, color); + color = settings.value(IniKey_ViewerColorFg).value(); + palette.setColor(QPalette::Text, color); + } + ui->viewerSample->setPalette(palette); + // フォント + if (!import) { + font = settings.value(IniKey_ViewerFont).value(); + ui->viewerFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize())); + ui->viewerSample->setFont(font); + } } -void PreferenceDialog::changeFont() +void PreferenceDialog::chooseFont() { + bool ok; QFont font; + QLabel *label = NULL; + + if (sender() == ui->chooseViewerFont) { + font = ui->viewerSample->font(); + } + else if (sender() == ui->chooseBoxFont) { + font = ui->sampleEdit->font(); + } + else if (sender() == ui->chooseViewFont) { + font = m_model.font(); + } + + font = QFontDialog::getFont(&ok, font, this); - if (sender() == ui->boxFont || - sender() == ui->boxFontBold || - sender() == ui->boxFontSize) - { - font.setBold(ui->boxFontBold->isChecked()); - font.setPointSize(ui->boxFontSize->value()); - font.setFamily(ui->boxFont->currentText()); + if (sender() == ui->chooseViewerFont) { + ui->viewerSample->setFont(font); + label = ui->viewerFont; + } + else if (sender() == ui->chooseBoxFont) { ui->sampleEdit->setFont(font); + label = ui->boxFont; } - else { - font.setBold(ui->viewFontBold->isChecked()); - font.setPointSize(ui->viewFontSize->value()); - font.setFamily(ui->viewFont->currentText()); + else if (sender() == ui->chooseViewFont) { m_model.setFont(font); m_model.update(); + label = ui->viewFont; } + label->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize())); + } void PreferenceDialog::setControlsEnabled(bool enabled) @@ -283,6 +330,18 @@ void PreferenceDialog::setControlsEnabled(bool enabled) ui->relativeLeft->setEnabled(enabled); ui->relativeTop->setEnabled(enabled); } + else if (sender() == ui->viewerInherit) { + ui->viewerClrBg->setEnabled(!enabled); + ui->viewerClrFg->setEnabled(!enabled); + } + else if (sender() == ui->enableViewerIgnoreExt) { + ui->viewerIgnoreExt->setEnabled(enabled); + } +} + +void PreferenceDialog::setIgnoreExtDefault() +{ + ui->viewerIgnoreExt->setPlainText(ViewerIgnoreExt()); } void PreferenceDialog::selectBoxColor() @@ -303,12 +362,11 @@ void PreferenceDialog::selectBoxColor() if (sender() == ui->boxClrBg) { palette.setColor(QPalette::Base, color); - ui->sampleEdit->setPalette(palette); } else if (sender() == ui->boxClrFg) { palette.setColor(QPalette::Text, color); - ui->sampleEdit->setPalette(palette); } + ui->sampleEdit->setPalette(palette); } void PreferenceDialog::selectViewColor() @@ -325,6 +383,31 @@ void PreferenceDialog::selectViewColor() m_model.update(); } +void PreferenceDialog::selectViewerColor() +{ + QColor color; + QPalette palette = ui->viewerSample->palette(); + if (sender() == ui->viewerClrBg) { + color = palette.background().color(); + } + else if (sender() == ui->viewerClrFg) { + color = palette.text().color(); + } + + color = QColorDialog::getColor(color, this, tr("色選択")); + if (!color.isValid()) { + return; + } + + if (sender() == ui->viewerClrBg) { + palette.setColor(QPalette::Base, color); + } + else if (sender() == ui->viewerClrFg) { + palette.setColor(QPalette::Text, color); + } + ui->viewerSample->setPalette(palette); +} + void PreferenceDialog::browseApp() { QStringList list = QStandardPaths::standardLocations( @@ -364,7 +447,7 @@ void PreferenceDialog::importAppearance() } QSettings settings(path, QSettings::IniFormat); - loadAppearance(settings); + loadAppearance(settings, true); } void PreferenceDialog::exportAppearance() @@ -450,5 +533,18 @@ void PreferenceDialog::accept() settings.setValue(IniKey_TerminalOption, ui->termOpt->text().trimmed()); settings.setValue(IniKey_TerminalPath, ui->termPath->text().trimmed()); + //>>>>> テキストビューア + settings.setValue(IniKey_ViewerFont, ui->viewerSample->font()); + settings.setValue(IniKey_ViewerColorBg, ui->viewerSample->palette().base().color()); + settings.setValue(IniKey_ViewerColorFg, ui->viewerSample->palette().text().color()); + settings.setValue(IniKey_ViewerInherit, ui->viewerInherit->isChecked()); + settings.setValue(IniKey_ViewerForceOpen, !ui->enableViewerIgnoreExt->isChecked()); + QStringList list = ui->viewerIgnoreExt->toPlainText().split(",", QString::SkipEmptyParts); + QStringList::iterator it; + for (it = list.begin(); it != list.end(); it++) { + *it = it->trimmed(); + } + settings.setValue(IniKey_ViewerIgnoreExt, list.join(",")); + QDialog::accept(); } diff --git a/preferencedialog.h b/preferencedialog.h index b4a0ac5..9385208 100644 --- a/preferencedialog.h +++ b/preferencedialog.h @@ -25,13 +25,15 @@ private: ColorMap m_colorMap; void saveAppearance(QSettings &settings); - void loadAppearance(QSettings &settings); + void loadAppearance(QSettings &settings, bool import); private slots: - void changeFont(); + void chooseFont(); void setControlsEnabled(bool enabled); + void setIgnoreExtDefault(); void selectBoxColor(); void selectViewColor(); + void selectViewerColor(); void browseApp(); void importAppearance(); void exportAppearance(); diff --git a/preferencedialog.ui b/preferencedialog.ui index e8e4e90..3c45e8e 100644 --- a/preferencedialog.ui +++ b/preferencedialog.ui @@ -6,8 +6,8 @@ 0 0 - 631 - 569 + 549 + 478 @@ -26,13 +26,28 @@ Qt::StrongFocus - 0 + 4 起動と終了 + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -46,11 +61,23 @@ - 6 + 4 QLayout::SetFixedSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -82,6 +109,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -107,6 +149,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -147,9 +204,24 @@ + + 4 + QLayout::SetMinimumSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -181,6 +253,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -206,6 +293,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -246,9 +348,24 @@ + + 4 + QLayout::SetMinimumSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -293,11 +410,23 @@ - 6 + 4 QLayout::SetFixedSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -329,6 +458,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -354,6 +498,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -394,9 +553,24 @@ + + 4 + QLayout::SetMinimumSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -428,6 +602,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -453,6 +642,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -493,9 +697,24 @@ + + 4 + QLayout::SetMinimumSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -529,9 +748,24 @@ + + 4 + QLayout::SetMinimumSize + + 4 + + + 4 + + + 4 + + + 4 + @@ -613,49 +847,80 @@ 色とフォント + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + アドレスボックス + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + - フォント - - - - - - - true - - - - - - - 1 + フォント: - + - pt + font family, point - + Qt::StrongFocus - 太字 + 選択 @@ -672,10 +937,6 @@ - - - - @@ -702,6 +963,25 @@ + + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -720,39 +1000,59 @@ ファイルビュー + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + - フォント - - - - - - - - - - 1 + フォント: - + - pt + font family, point - + Qt::StrongFocus - 太字 + 選択 @@ -769,146 +1069,175 @@ + + + + Qt::StrongFocus + + + 文字色 + + + + + + + Qt::StrongFocus + + + 背景色 + + + - + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + - - - - - - - 文字色 - - - - - - - - Qt::StrongFocus - - - 通常 - - - - - - - Qt::StrongFocus - - - マーク - - - - - - - - - - - Qt::StrongFocus - - - システム - - - - - - - Qt::StrongFocus - - - 隠し属性 - - - - - - - Qt::StrongFocus - - - 読取専用 - - - - - - - - - - - - 背景色 - - - - - - Qt::StrongFocus - - - 通常 - - - - - - - Qt::StrongFocus - - - マーク - - - - - - - - - + + + 文字色 + + + + + + Qt::StrongFocus + + + システム + + + + + + + Qt::StrongFocus + + + マーク + + + + + + + Qt::StrongFocus + + + 隠し属性 + + + + + + + Qt::StrongFocus + + + 読取専用 + + + + + - - - - 0 - 0 - - - - - 200 - 0 - - - - Qt::NoFocus + + + 背景色 - - false - - - false - + + + + + Qt::StrongFocus + + + マーク + + + + + + + + + 0 + 0 + + + + + 0 + 110 + + + + Qt::NoFocus + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + Qt::ElideMiddle + + + false + + + false + + + false + + + false + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -964,12 +1293,42 @@ ファイル操作 + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + 操作の開始時、確認ダイアログを表示する + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -1032,6 +1391,21 @@ 操作の成功時、進捗ダイアログを自動で閉じる + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -1094,6 +1468,21 @@ 同名ファイル存在時の既定の動作 + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -1202,15 +1591,54 @@ パス設定 + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + - 0 + 4 + + + 4 + + + 4 + + + 4 + + + 4 - -1 + 4 + + + 4 + + + 4 + + + 4 + + + 4 @@ -1233,6 +1661,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -1263,12 +1706,36 @@ - 0 + 4 + + + 4 + + + 4 + + + 4 + + + 4 - -1 + 4 + + + 4 + + + 4 + + + 4 + + + 4 @@ -1291,6 +1758,21 @@ + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -1353,6 +1835,316 @@ $P ... フルパス($D/$Fと同じ) optExplain + + + テキストビューア + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + 外観 + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + フォント: + + + + + + + font family, point + + + + + + + Qt::StrongFocus + + + 選択 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + 文字色 + + + + + + + Qt::StrongFocus + + + 背景色 + + + + + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 文字色と背景色はファイルビューを継承 + + + + + + + + + true + + + 01234567890 +abcdefghijklmnopqrstuvwxyz +ABCDEFGHIJKLMNOPQRSTUVWXYZ +!"#$%&'()+-*=^~¥|@`[]{}<>;:,./?_ +あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。 + + + + + + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + 以下の拡張子は、外部アプリを優先する + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + デフォルトに戻す + + + + + + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 17 + + + + + + + + + 0 + 0 + + + + + 0 + 100 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 3 + + + + + + @@ -1371,6 +2163,7 @@ $P ... フルパス($D/$Fと同じ) + tabWidget bootSize sizeAbsolute absoluteWidth @@ -1389,22 +2182,53 @@ $P ... フルパス($D/$Fと同じ) posCenter posLast resetOnBoot - boxFont - boxFontSize - boxFontBold + confirmExit + chooseBoxFont boxClrFg boxClrBg sampleEdit - viewFont - viewFontSize - viewFontBold + chooseViewFont clrFgNormal - clrFgMark + clrBgNormal clrFgSystem + clrFgMark clrFgHidden clrFgReadonly - clrBgNormal clrBgMark + importAppearance + exportAppearance + confirmCopy + confirmMove + confirmDelete + confirmRename + autoCloseCopy + autoCloseMove + autoCloseDelete + autoCloseRename + owDefOverWrite + owDefIfNew + owDefSkip + owDefAppendNumber + owDefRename + moveAfterCreate + openAfterCreate + editorPath + editorBrowse + editorOpt + termPath + termBrowse + termOpt + optExplain + chooseViewerFont + viewerClrFg + viewerClrBg + viewerInherit + viewerSample + enableViewerIgnoreExt + defaultIgnoreExt + viewerIgnoreExt + buttonBox + checkUpdates @@ -1442,8 +2266,8 @@ $P ... フルパス($D/$Fと同じ) - + diff --git a/simpletextview.cpp b/simpletextview.cpp index e303f58..67f8018 100644 --- a/simpletextview.cpp +++ b/simpletextview.cpp @@ -7,6 +7,7 @@ #include #include #include +#include SimpleTextView::SimpleTextView(QWidget *parent) : QPlainTextEdit(parent), @@ -41,6 +42,7 @@ SimpleTextView::SimpleTextView(QWidget *parent) : m_convJIS = new QAction(tr("ISO 2022-JP(JIS)で再読込"), this); m_convSJIS = new QAction(tr("Shift-JISで再読込"), this); m_convUTF8 = new QAction(tr("UTF-8で再読込"), this); + m_convUTF16 = new QAction(tr("UTF-16で再読込"), this); m_convUTF16BE = new QAction(tr("UTF-16BEで再読込"), this); m_convUTF16LE = new QAction(tr("UTF-16LEで再読込"), this); m_back = new QAction(tr("戻る"), this); @@ -49,14 +51,16 @@ SimpleTextView::SimpleTextView(QWidget *parent) : m_convJIS->setShortcut(QKeySequence("J")); m_convSJIS->setShortcut(QKeySequence("S")); m_convUTF8->setShortcut(QKeySequence("U")); - m_convUTF16BE->setShortcut(QKeySequence("B")); - m_convUTF16LE->setShortcut(QKeySequence("L")); + m_convUTF8->setShortcut(QKeySequence("I")); + m_convUTF16BE->setShortcut(QKeySequence("J")); + m_convUTF16LE->setShortcut(QKeySequence("N")); m_back->setShortcut(QKeySequence("Return")); connect(m_convEUC, SIGNAL(triggered()), this, SLOT(convertFromEUC())); connect(m_convJIS, SIGNAL(triggered()), this, SLOT(convertFromJIS())); connect(m_convSJIS, SIGNAL(triggered()), this, SLOT(convertFromSJIS())); connect(m_convUTF8, SIGNAL(triggered()), this, SLOT(convertFromUTF8())); + connect(m_convUTF16, SIGNAL(triggered()), this, SLOT(convertFromUTF16())); connect(m_convUTF16BE, SIGNAL(triggered()), this, SLOT(convertFromUTF16BE())); connect(m_convUTF16LE, SIGNAL(triggered()), this, SLOT(convertFromUTF16LE())); connect(m_back, SIGNAL(triggered()), this, SLOT(back())); @@ -65,10 +69,190 @@ SimpleTextView::SimpleTextView(QWidget *parent) : void SimpleTextView::setSource(const QByteArray &source) { m_source = source; -#ifdef Q_OS_MAC - convertFromUTF8(); + + // BOMで文字コードを判別する + const char UTF8_BOM[] = { 0xEF, 0xBB, 0xBF }; + const char UTF16BE_BOM[] = { 0xFE, 0xFF }; + const char UTF16LE_BOM[] = { 0xFF, 0xFE }; + + if (m_source.indexOf(QByteArray(UTF8_BOM)) == 0) { + qDebug() << "Detect UTF-8 BOM"; + convertFromUTF8(); + } + else if (m_source.indexOf(QByteArray(UTF16BE_BOM)) == 0 || + m_source.indexOf(QByteArray(UTF16LE_BOM)) == 0) + { + qDebug() << "Detect UTF-16 BOM"; + convertFromUTF16(); + } + + QByteArray first1KB = m_source.left(1024); + // 文字コードを示す文字列で判別する + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); + QString text = codec->toUnicode(first1KB).toLower(); + if (text.indexOf("utf8") != -1 || text.indexOf("utf-8") != -1) { + convertFromUTF8(); + return; + } + if (text.indexOf("sjis") != -1 || text.indexOf("shift-jis") != -1 || + text.indexOf("shift_jis") != -1) + { + convertFromSJIS(); + return; + } + if (text.indexOf("euc") != -1 || text.indexOf("euc-jp") != -1 || + text.indexOf("euc_jp") != -1) + { + convertFromEUC(); + return; + } + if (text.indexOf("jis") != -1 || text.indexOf("iso 2022-jp") != -1) { + convertFromJIS(); + return; + } + + std::string code = detectCode(first1KB); + codec = QTextCodec::codecForName(code.c_str()); + setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage(code.c_str()); +} + +// http://dobon.net/vb/dotnet/string/detectcode.html より拝借 +std::string SimpleTextView::detectCode(const QByteArray &bytes) +{ + typedef unsigned char byte; + const byte bEscape = 0x1B; + const byte bAt = 0x40; + const byte bDollar = 0x24; + const byte bAnd = 0x26; + const byte bOpen = 0x28; //'(' + const byte bB = 0x42; + const byte bD = 0x44; + const byte bJ = 0x4A; + const byte bI = 0x49; + + int len = bytes.size(); + byte b1, b2, b3, b4; + + bool isBinary = false; + for (int i = 0; i < len; i++) { + b1 = bytes[i]; + if (b1 <= 0x06 || b1 == 0x7F || b1 == 0xFF) { + //'binary' + isBinary = true; + if (b1 == 0x00 && i < len - 1 && bytes[i + 1] <= 0x7F) { + return "UTF-16LE"; + } + } + } + if (isBinary) { + return "UTF-8"; + } + + bool notJapanese = true; + for (int i = 0; i < len; i++) { + b1 = bytes[i]; + if (b1 == bEscape || 0x80 <= b1) { + notJapanese = false; + break; + } + } + if (notJapanese) { + return "UTF-8"; + } + + for (int i = 0; i < len - 2; i++) { + b1 = bytes[i]; + b2 = bytes[i + 1]; + b3 = bytes[i + 2]; + + if (b1 == bEscape){ + if ((b2 == bDollar && b3 == bAt) || + (b2 == bDollar && b3 == bB) || + (b2 == bOpen && (b3 == bB || b3 == bJ)) || + (b2 == bOpen && b3 == bI)) + { + return "ISO 2022-JP"; + } + if (i < len - 3) { + b4 = bytes[i + 3]; + if (b2 == bDollar && b3 == bOpen && b4 == bD) { + return "ISO 2022-JP"; + } + if (i < len - 5 && + b2 == bAnd && b3 == bAt && b4 == bEscape && + bytes[i + 4] == bDollar && bytes[i + 5] == bB) + { + return "ISO 2022-JP"; + } + } + } + } + + int sjis = 0; + int euc = 0; + int utf8 = 0; + for (int i = 0; i < len - 1; i++) { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if (((0x81 <= b1 && b1 <= 0x9F) || (0xE0 <= b1 && b1 <= 0xFC)) && + ((0x40 <= b2 && b2 <= 0x7E) || (0x80 <= b2 && b2 <= 0xFC))) + { + sjis += 2; + i++; + } + } + for (int i = 0; i < len - 1; i++) { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if (((0xA1 <= b1 && b1 <= 0xFE) && (0xA1 <= b2 && b2 <= 0xFE)) || + (b1 == 0x8E && (0xA1 <= b2 && b2 <= 0xDF))) + { + euc += 2; + i++; + } + else if (i < len - 2) { + b3 = bytes[i + 2]; + if (b1 == 0x8F && (0xA1 <= b2 && b2 <= 0xFE) && + (0xA1 <= b3 && b3 <= 0xFE)) + { + euc += 3; + i += 2; + } + } + } + for (int i = 0; i < len - 1; i++) { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if ((0xC0 <= b1 && b1 <= 0xDF) && (0x80 <= b2 && b2 <= 0xBF)) { + utf8 += 2; + i++; + } + else if (i < len - 2) { + b3 = bytes[i + 2]; + if ((0xE0 <= b1 && b1 <= 0xEF) && (0x80 <= b2 && b2 <= 0xBF) && + (0x80 <= b3 && b3 <= 0xBF)) + { + utf8 += 3; + i += 2; + } + } + } + + if (euc > sjis && euc > utf8) { + return "EUC-JP"; + } + else if (sjis > euc && sjis > utf8) { + return "Shift-JIS"; + } + else if (utf8 > euc && utf8 > sjis) { + return "UTF-8"; + } + +#ifdef Q_OS_WIN + return "Shift-JIS"; #else - convertFromSJIS(); + return "UTF-8"; #endif } @@ -76,36 +260,50 @@ void SimpleTextView::convertFromEUC() { QTextCodec *codec = QTextCodec::codecForName("EUC-JP"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("EUC-JP"); } void SimpleTextView::convertFromJIS() { QTextCodec *codec = QTextCodec::codecForName("ISO 2022-JP"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("ISO 2022-JP"); } void SimpleTextView::convertFromSJIS() { QTextCodec *codec = QTextCodec::codecForName("Shift-JIS"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("Shift-JIS"); + } void SimpleTextView::convertFromUTF8() { QTextCodec *codec = QTextCodec::codecForName("UTF-8"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("UTF-8"); +} + +void SimpleTextView::convertFromUTF16() +{ + QTextCodec *codec = QTextCodec::codecForName("UTF-16"); + setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("UTF-16"); } void SimpleTextView::convertFromUTF16BE() { QTextCodec *codec = QTextCodec::codecForName("UTF-16BE"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("UTF-16BE"); } void SimpleTextView::convertFromUTF16LE() { QTextCodec *codec = QTextCodec::codecForName("UTF-16LE"); setPlainText(codec->toUnicode(m_source)); + getMainWnd()->statusBar()->showMessage("UTF-16LE"); } void SimpleTextView::back() diff --git a/simpletextview.h b/simpletextview.h index 6361e80..5eecd3b 100644 --- a/simpletextview.h +++ b/simpletextview.h @@ -16,11 +16,14 @@ private: QAction *m_convJIS; QAction *m_convSJIS; QAction *m_convUTF8; + QAction *m_convUTF16; QAction *m_convUTF16BE; QAction *m_convUTF16LE; QAction *m_back; QByteArray m_source; + std::string detectCode(const QByteArray &bytes); + signals: void viewFinished(QWidget *sender); @@ -31,6 +34,7 @@ private slots: void convertFromJIS(); void convertFromSJIS(); void convertFromUTF8(); + void convertFromUTF16(); void convertFromUTF16BE(); void convertFromUTF16LE(); void back();