Wt examples
3.2.3
|
00001 // This may look like C code, but it's really -*- C++ -*- 00002 /* 00003 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium. 00004 * 00005 * See the LICENSE file for terms of use. 00006 */ 00007 00008 #include "OptionList.h" 00009 #include "Option.h" 00010 00011 OptionList::OptionList(WContainerWidget *parent) 00012 : WContainerWidget(parent), 00013 optionNeedReset_(0) 00014 { 00015 resize(WLength::Auto, WLength(2.5, WLength::FontEx)); 00016 } 00017 00018 void OptionList::add(Option *option) 00019 { 00020 addWidget(option); 00021 option->setOptionList(this); 00022 00023 if (!options_.empty()) { 00024 options_.back()->addSeparator(); 00025 } 00026 00027 options_.push_back(option); 00028 } 00029 00030 void OptionList::update() 00031 { 00032 if (optionNeedReset_ != 0) 00033 optionNeedReset_->resetLearnedSlots(); 00034 00035 optionNeedReset_ = 0; 00036 } 00037 00038 void OptionList::optionVisibilityChanged(Option *opt, bool hidden) 00039 { 00040 /* 00041 * Check if it was the last visible option, in that case the second last 00042 * visible option loses its separator. 00043 */ 00044 for (std::size_t i = options_.size() - 1; i > 0; --i) { 00045 if (options_[i] == opt) { 00046 for (int j = i - 1; j >= 0; --j) { 00047 if (!options_[j]->isHidden()) { 00048 if (hidden) 00049 options_[j]->hideSeparator(); 00050 else 00051 options_[j]->showSeparator(); 00052 break; 00053 } 00054 } 00055 break; 00056 } else 00057 if (!options_[i]->isHidden()) 00058 break; 00059 } 00060 00061 /* 00062 * The Option to the right needs to relearn its stateless 00063 * slot code for hide() and show(). 00064 */ 00065 for (unsigned i = 0; i < options_.size(); ++i) { 00066 if (options_[i] == opt) { 00067 for (unsigned j = i + 1; j < options_.size(); ++j) { 00068 if (!options_[j]->isHidden()) { 00069 optionNeedReset_ = options_[j]; 00070 break; 00071 } 00072 } 00073 00074 break; 00075 } 00076 } 00077 } 00078