diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 1d31c8396..51bfc96cc 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include #include @@ -213,6 +216,7 @@ void CS::Editor::createNewFile (const boost::filesystem::path &savePath) mDocumentManager.addDocument (files, savePath, true); mFileDialog.hide(); + showSplashMessage(); } void CS::Editor::createNewGame (const boost::filesystem::path& file) @@ -224,6 +228,7 @@ void CS::Editor::createNewGame (const boost::filesystem::path& file) mDocumentManager.addDocument (files, file, true); mNewGame.hide(); + showSplashMessage(); } void CS::Editor::showStartup() @@ -435,9 +440,51 @@ std::auto_ptr CS::Editor::setupGraphics() void CS::Editor::documentAdded (CSMDoc::Document *document) { mViewManager.addView (document); + showSplashMessage(); } void CS::Editor::lastDocumentDeleted() { QApplication::quit(); } + +void CS::Editor::showSplashMessage() +{ + CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); + if(settings.settingValue ("filter/project-added") == "true" || + settings.settingValue ("filter/project-modified") == "true") + { + QPixmap img(QPixmap(":./openmw-cs.png")); + + QString msgTop("You have active global filters."); + QString msgBottom("Some rows may be hidden!"); + QFont splashFont(QFont("Arial", 16, QFont::Bold)); // TODO: use system font? + //splashFont.setStretch(125); + + QFontMetrics fm(splashFont); + int msgWidth = std::max(fm.width(msgTop), fm.width(msgBottom)); + img.scaledToWidth(msgWidth); + + QSplashScreen *splash = new QSplashScreen(img, Qt::WindowStaysOnTopHint); + splash->setFont(splashFont); + splash->resize(msgWidth+20, splash->height()+fm.lineSpacing()*2+20); // add some margin + + // try to center the message near the center of the saved window + QWidget dummy; + bool xWorkaround = settings.settingValue ("window/x-save-state-workaround").toStdString() == "true"; + if (settings.settingValue ("window/save-state").toStdString() == "true" && + !(xWorkaround && settings.settingValue ("window/maximized").toStdString() == "true")) + { + dummy.restoreGeometry(settings.value("window/geometry").toByteArray()); + splash->move(dummy.x()+std::max(0, (dummy.width()-msgWidth)/2), + dummy.y()+std::max(0, (dummy.height()-splash->height())/2)); + } + else + splash->move(std::max(0, splash->x()-msgWidth/2), splash->y()); + + splash->show(); + splash->showMessage(msgTop+"\n"+msgBottom, Qt::AlignHCenter|Qt::AlignBottom, Qt::red); + QTimer::singleShot(4000, splash, SLOT(close())); // 4 seconds should be enough + splash->raise(); // for X windows + } +} diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 273f0825b..3935ac56a 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -60,6 +60,8 @@ namespace CS boost::filesystem::ofstream mPidFile; bool mFsStrict; + void showSplashMessage(); + void setupDataFiles (const Files::PathContainer& dataDirs); std::pair > readConfig(); diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 491e70a88..f3de34484 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -241,13 +241,26 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() Setting *lineNum = createSetting (Type_CheckBox, "show-linenum", "Show Line Numbers"); lineNum->setDefaultValue ("true"); lineNum->setToolTip ("Show line numbers to the left of the script editor window." - "The current row and column numbers of the text cursor are shown at the bottom."); + " The current row and column numbers of the text cursor are shown at the bottom."); Setting *monoFont = createSetting (Type_CheckBox, "mono-font", "Use monospace font"); monoFont->setDefaultValue ("true"); monoFont->setToolTip ("Whether to use monospaced fonts on script edit subview."); } + declareSection ("filter", "Global Filter"); + { + Setting *projAdded = createSetting (Type_CheckBox, "project-added", "Project::added initial value"); + projAdded->setDefaultValue ("false"); + projAdded->setToolTip ("Show records added by the project when opening a table." + " Other records are filterd out."); + + Setting *projModified = createSetting (Type_CheckBox, "project-modified", "Project::modified initial value"); + projModified->setDefaultValue ("false"); + projModified->setToolTip ("Show records modified by the project when opening a table." + " Other records are filterd out."); + } + { /****************************************************************** * There are three types of values: diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 5a650f98a..2314a9397 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -21,6 +21,10 @@ #include "../../model/world/tablemimedata.hpp" #include "../../model/world/tablemimedata.hpp" #include "../../model/world/commanddispatcher.hpp" +#include "../../model/filter/parser.hpp" +#include "../../model/filter/andnode.hpp" +#include "../../model/filter/ornode.hpp" +#include "../../model/settings/usersettings.hpp" #include "recordstatusdelegate.hpp" #include "util.hpp" @@ -362,6 +366,24 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, mDoubleClickActions.insert (std::make_pair (Qt::ShiftModifier, Action_EditRecord)); mDoubleClickActions.insert (std::make_pair (Qt::ControlModifier, Action_View)); mDoubleClickActions.insert (std::make_pair (Qt::ShiftModifier | Qt::ControlModifier, Action_EditRecordAndClose)); + + CSMFilter::Parser parser(mDocument.getData()); + + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + if(userSettings.settingValue ("filter/project-added") == "true") + { + parser.parse("!string(\"Modified\", \"Added\")"); + mAdded = parser.getFilter(); + } + + if(userSettings.settingValue ("filter/project-modified") == "true") + { + parser.parse("!string(\"Modified\", \"Modified\")"); + mModified = parser.getFilter(); + } + + if(mAdded || mModified) + recordFilterChanged(boost::shared_ptr()); } void CSVWorld::Table::setEditLock (bool locked) @@ -517,8 +539,7 @@ void CSVWorld::Table::previewRecord() } } -void CSVWorld::Table::updateUserSetting - (const QString &name, const QStringList &list) +void CSVWorld::Table::updateUserSetting (const QString &name, const QStringList &list) { if (name=="records/type-format" || name=="records/status-format") { @@ -626,7 +647,37 @@ void CSVWorld::Table::requestFocus (const std::string& id) void CSVWorld::Table::recordFilterChanged (boost::shared_ptr filter) { - mProxyModel->setFilter (filter); + mFilter = filter; + + boost::shared_ptr global; + if(mAdded && mModified) + { + std::vector > nodes; + nodes.push_back(mAdded); + nodes.push_back(mModified); + global = boost::shared_ptr(new CSMFilter::OrNode (nodes)); + } + else if(mAdded) + { + global = mAdded; + } + else if(mModified) + { + global = mModified; + } + + if(filter && global) + { + std::vector > nodes; + nodes.push_back(filter); + nodes.push_back(global); + boost::shared_ptr combined(new CSMFilter::AndNode (nodes)); + mProxyModel->setFilter (combined); + } + else if(global) + mProxyModel->setFilter (global); + else + mProxyModel->setFilter (filter); tableSizeUpdate(); selectionSizeUpdate(); } @@ -700,3 +751,30 @@ std::vector< CSMWorld::UniversalId > CSVWorld::Table::getDraggedRecords() const return idToDrag; } +void CSVWorld::Table::globalFilterAddedChanged(int state) +{ + if(state == Qt::Checked && !mAdded) + { + CSMFilter::Parser parser(mDocument.getData()); + parser.parse("!string(\"Modified\", \"Added\")"); + mAdded = parser.getFilter(); + } + else if(state == Qt::Unchecked) + mAdded.reset(); + + recordFilterChanged(mFilter); +} + +void CSVWorld::Table::globalFilterModifiedChanged(int state) +{ + if(state == Qt::Checked && !mModified) + { + CSMFilter::Parser parser(mDocument.getData()); + parser.parse("!string(\"Modified\", \"Modified\")"); + mModified = parser.getFilter(); + } + else if(state == Qt::Unchecked) + mModified.reset(); + + recordFilterChanged(mFilter); +} diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 75161b8b6..e87828e2f 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -68,6 +68,10 @@ namespace CSVWorld CSMWorld::UniversalId mEditCellId; std::map mDoubleClickActions; + boost::shared_ptr mFilter; + boost::shared_ptr mAdded; + boost::shared_ptr mModified; + private: void contextMenuEvent (QContextMenuEvent *event); @@ -139,6 +143,9 @@ namespace CSVWorld void recordFilterChanged (boost::shared_ptr filter); void updateUserSetting (const QString &name, const QStringList &list); + + void globalFilterAddedChanged (int state); + void globalFilterModifiedChanged (int state); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 729b6b8d7..40b52709e 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -1,11 +1,14 @@ #include "tablesubview.hpp" +#include +#include #include #include #include "../../model/doc/document.hpp" #include "../../model/world/tablemimedata.hpp" +#include "../../model/settings/usersettings.hpp" #include "../filter/filterbox.hpp" #include "table.hpp" @@ -28,7 +31,21 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D mFilterBox = new CSVFilter::FilterBox (document.getData(), this); - layout->insertWidget (0, mFilterBox); + QHBoxLayout *hLayout = new QHBoxLayout; + QCheckBox *added = new QCheckBox("A"); + QCheckBox *modified = new QCheckBox("M"); + added->setToolTip("Apply filter project::added. Changes to\nthis filter setting is not saved in preferences."); + modified->setToolTip("Apply filter project::modified. Changes to\nthis filter setting is not saved in preferences."); + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + added->setCheckState( + userSettings.settingValue ("filter/project-added") == "true" ? Qt::Checked : Qt::Unchecked); + modified->setCheckState( + userSettings.settingValue ("filter/project-modified") == "true" ? Qt::Checked : Qt::Unchecked); + + hLayout->insertWidget(0,mFilterBox); + hLayout->insertWidget(1,added); + hLayout->insertWidget(2,modified); + layout->insertLayout (0, hLayout); QWidget *widget = new QWidget; @@ -44,6 +61,9 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D connect (mTable, SIGNAL (tableSizeChanged (int, int, int)), mBottom, SLOT (tableSizeChanged (int, int, int))); + connect(added, SIGNAL (stateChanged(int)), mTable, SLOT (globalFilterAddedChanged(int))); + connect(modified, SIGNAL (stateChanged(int)), mTable, SLOT (globalFilterModifiedChanged(int))); + mTable->tableSizeUpdate(); mTable->selectionSizeUpdate(); mTable->viewport()->installEventFilter(this); @@ -84,8 +104,7 @@ void CSVWorld::TableSubView::editRequest (const CSMWorld::UniversalId& id, const focusId (id, hint); } -void CSVWorld::TableSubView::updateUserSetting - (const QString &name, const QStringList &list) +void CSVWorld::TableSubView::updateUserSetting (const QString &name, const QStringList &list) { mTable->updateUserSetting(name, list); }