File indexing completed on 2024-12-01 06:51:46
0001 /*************************************************************************** 0002 cmapmudviewstatusbar.cpp 0003 ------------------- 0004 begin : Thu May 10 2001 0005 copyright : (C) 2001 by Kmud Developer Team 0006 email : kmud-devel@kmud.de 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "cmapviewstatusbar.h" 0019 0020 #include <QLabel> 0021 #include <QComboBox> 0022 #include <QPushButton> 0023 0024 #include <KLocalizedString> 0025 0026 #include "cmapzone.h" 0027 #include "cmapzonemanager.h" 0028 #include "cmapview.h" 0029 #include "cmapmanager.h" 0030 #include "cmaplevel.h" 0031 0032 struct CMapViewStatusbar::Private { 0033 CMapManager *manager; 0034 0035 QLabel *lblRoomLabel; 0036 QLabel *lblLevelLabel; 0037 QLabel *lblZoneLabel; 0038 0039 QLabel *lblRoomStatus; 0040 QComboBox *levelPicker; 0041 QComboBox *zonePicker; 0042 0043 CMapZone *zone; 0044 CMapLevel *level; 0045 }; 0046 0047 CMapViewStatusbar::CMapViewStatusbar(CMapManager *manager, QWidget *parent) : QStatusBar(parent) 0048 { 0049 d = new Private; 0050 d->manager = manager; 0051 d->zone = nullptr; 0052 d->level = nullptr; 0053 0054 // labels 0055 d->lblRoomLabel = new QLabel(i18n("Current Room : "), this); 0056 d->lblLevelLabel = new QLabel(i18n("Level : "),this); 0057 d->lblZoneLabel = new QLabel(i18n("Zone : "),this); 0058 0059 QFont f = d->lblRoomLabel->font(); 0060 f.setItalic(true); 0061 d->lblRoomStatus = new QLabel(i18n("Unknown"),this); 0062 d->lblRoomStatus->setFont(f); 0063 d->levelPicker = new QComboBox(this); 0064 d->levelPicker->setFont(f); 0065 d->levelPicker->setEditable(true); 0066 d->levelPicker->setInsertPolicy(QComboBox::NoInsert); 0067 connect(d->levelPicker, SIGNAL(activated(int)), this, SLOT(changeLevel(int))); 0068 connect(d->levelPicker, SIGNAL(editTextChanged(const QString &)), this, SLOT(renameLevel(const QString &))); 0069 0070 d->zonePicker = new QComboBox(this); 0071 d->zonePicker->setFont(f); 0072 d->zonePicker->setEditable(true); 0073 d->zonePicker->setInsertPolicy(QComboBox::NoInsert); 0074 connect(d->zonePicker, SIGNAL(activated(int)), this, SLOT(changeZone(int))); 0075 connect(d->zonePicker, SIGNAL(editTextChanged(const QString &)), this, SLOT(renameZone(const QString &))); 0076 0077 addWidget(d->lblZoneLabel); 0078 addWidget(d->zonePicker); 0079 addWidget(d->lblLevelLabel); 0080 addWidget(d->levelPicker); 0081 addWidget(d->lblRoomLabel); 0082 addWidget(d->lblRoomStatus); 0083 } 0084 0085 CMapViewStatusbar::~CMapViewStatusbar() 0086 { 0087 delete d; 0088 } 0089 0090 void CMapViewStatusbar::setLevel(CMapLevel *lvl) 0091 { 0092 d->level = lvl; 0093 int idx = d->zone->levelIndex(lvl); 0094 d->levelPicker->setCurrentIndex(idx); 0095 } 0096 0097 void CMapViewStatusbar::setZone(CMapZone *zone) 0098 { 0099 // this is because we can't set the model in the constructor, as the zone manager doesn't yet exist 0100 CMapZoneManager *zones = d->manager->zoneManager(); 0101 if (zones) { 0102 if (d->zonePicker->model() != zones->zonesModel()) 0103 d->zonePicker->setModel(zones->zonesModel()); 0104 d->zonePicker->setCurrentIndex(zones->activeZone()); 0105 } 0106 0107 d->zone = zone; 0108 d->levelPicker->setModel(zone->levelsModel()); 0109 setLevel(d->manager->getActiveView()->getCurrentlyViewedLevel()); 0110 } 0111 0112 void CMapViewStatusbar::setRoom(QString room) 0113 { 0114 if (room.isEmpty()) room = "Unknown"; 0115 d->lblRoomStatus->setText(room); 0116 } 0117 0118 void CMapViewStatusbar::addFollowButton(QPushButton *button) 0119 { 0120 addPermanentWidget(button); 0121 } 0122 0123 void CMapViewStatusbar::changeLevel(int index) 0124 { 0125 CMapLevel *level = d->zone->getLevel(index); 0126 if (!level) return; 0127 d->manager->displayLevel(level, false); 0128 } 0129 0130 void CMapViewStatusbar::renameLevel(const QString &name) 0131 { 0132 if (!d->zone) return; 0133 0134 // apparently this also gets called when we switch to a new level - then we do not want to rename anything 0135 int idx = d->zone->levelIndex(d->level); 0136 if (idx != d->levelPicker->currentIndex()) return; 0137 0138 d->level->setName (name); 0139 } 0140 0141 void CMapViewStatusbar::changeZone(int index) 0142 { 0143 d->manager->zoneManager()->loadZone(index); 0144 } 0145 0146 void CMapViewStatusbar::renameZone(const QString &name) 0147 { 0148 // apparently this also gets called when we switch to a new zone - then we do not want to rename anything 0149 int idx = d->manager->zoneManager()->activeZone(); 0150 if (idx != d->zonePicker->currentIndex()) return; 0151 0152 d->manager->zoneManager()->renameZone(idx, name); 0153 } 0154 0155 #include "moc_cmapviewstatusbar.cpp"