8 #include <QGraphicsEllipseItem> 
   12 #include <QDragEnterEvent> 
   14 #include <QApplication> 
   17 #include <QInputDialog> 
   67   static void wrap(QList<VP1Interval>&);
 
   88                          bool& allOn, 
bool& allOff) 
const;
 
  113   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
  114   setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
  115   setRenderHint(QPainter::Antialiasing,
true);
 
  128   setFocusPolicy(Qt::NoFocus);
 
  129   setAcceptDrops(
true);
 
  133   QList<int> defaultAllowedNSectors;
 
  134   defaultAllowedNSectors <<  4 <<  5 <<  6 <<  8 << 9 << 10
 
  135              << 12 << 16 << 24 << 32 << 36 << 48 << 64;
 
  144   QGraphicsScene * oldscene = scene();
 
  160   if (nsectors<4||nsectors>99) {
 
  171     for(
int i = 2; 
i < 100; ++
i) {
 
  180        messageDebug(
"!sectorstatus.isEmpty() && nsectors==sectorstatus.count(). Returning...");
 
  192   QList<VP1Interval> oldEnabledRanges;
 
  202   QGraphicsScene * oldscene = scene();
 
  203   setScene(
new QGraphicsScene);
 
  207   const double R = 10.0;
 
  208   const double r = (2*
M_PI)*
R / nsectors / 1.2;
 
  210   for (
int isector = 0; isector < nsectors; ++isector) {
 
  211     double phi = (isector+0.5)*(2*
M_PI)/nsectors;
 
  213     QGraphicsEllipseItem * ellipse = scene()->addEllipse(
x,
y,
r,
r);
 
  219   if (!forceAllEnabled)
 
  222   fitInView(scene()->sceneRect());
 
  230   if (nsectors <= 12) { 
 
  232   } 
else if(nsectors >= 16 && nsectors < 24) {
 
  233       setFixedSize(120,120);
 
  234   } 
else if(nsectors >= 24 && nsectors < 32) {
 
  235       setFixedSize(200,200);
 
  236   } 
else if (nsectors >= 32 && nsectors <= 36) {
 
  237       setFixedSize(300,300);
 
  238   } 
else if (nsectors > 36) { 
 
  239       setFixedSize(400,400);
 
  245        messageDebug(
"WARNING. m_d->sectorstatus is still Empty...");
 
  289   popup_menu = 
new QMenu(theclass);
 
  290   popup_copyAction =  popup_menu->addAction(
"&Copy");
 
  291   popup_pasteAction =  popup_menu->addAction(
"&Paste");
 
  292   popup_menu->addSeparator();
 
  293   popup_enableAllAction = popup_menu->addAction(
"&Enable all sectors");
 
  294   popup_disableAllAction = popup_menu->addAction(
"&Disable all sectors");
 
  295   popup_invertAction =  popup_menu->addAction(
"&Invert");
 
  296   popup_menu->addSeparator();
 
  297   popup_setNPhiSubMenu = popup_menu->addMenu(
"&Set number of phi sectors");
 
  298   addMenuEntriesForSetNPhi();
 
  306   if (!popuplist_setNPhi.isEmpty()) {
 
  307     for(QAction * setNPhiAct : popuplist_setNPhi)
 
  310   popuplist_setNPhi.clear();
 
  312   for(
int nSectors : allowedNSectors) {
 
  314     a->setData(nSectors);
 
  315     popuplist_setNPhi << 
a;
 
  317   if (allowCustomNSectors) {
 
  318     popup_setNPhiSubMenu->addSeparator();
 
  319     popup_setCustomNPhi = popup_setNPhiSubMenu->addAction(
"&Custom...");
 
  331   QClipboard * clipboard = QApplication::clipboard();
 
  333            &&clipboard->mimeData()->hasFormat(
"vp1/enabledphisectors"));
 
  337     int nSectors = setNPhiAct->data().toInt(&ok);
 
  346     QMimeData *mimeData = 
new QMimeData;
 
  347     mimeData->setData(
"vp1/enabledphisectors", 
state());
 
  349     clipboard->setMimeData(mimeData);
 
  353     QByteArray 
data = clipboard->mimeData()->data(
"vp1/enabledphisectors");
 
  381     int nCustomSectors = QInputDialog::getInt(
this, 
"Set number of phi sectors",
 
  383     if (ok && nCustomSectors >= 4 && nCustomSectors <= 99 )
 
  389     int nSectors = selAct->data().toInt(&ok);
 
  399   if (
event->buttons()==Qt::RightButton) {
 
  404   if (
event->button() == Qt::LeftButton)
 
  407   if (
event->buttons()!=Qt::LeftButton) {
 
  408     QGraphicsView::mousePressEvent(
event);
 
  411   QGraphicsItem *item_ = itemAt(
event->pos());
 
  412   QGraphicsEllipseItem * 
item = 
static_cast<QGraphicsEllipseItem*
>(item_);
 
  414     QGraphicsView::mousePressEvent(
event);
 
  419     QGraphicsView::mousePressEvent(
event);
 
  433   if (!(
event->buttons() & Qt::LeftButton))
 
  436       < QApplication::startDragDistance())
 
  439   QDrag *drag = 
new QDrag(
this);
 
  440   QMimeData *mimeData = 
new QMimeData;
 
  446   mimeData->setData(
"vp1/enabledphisectors", 
state());
 
  456   drag->setMimeData(mimeData);
 
  457   drag->exec(Qt::CopyAction | Qt::MoveAction);
 
  463   if (
event->source()!=
this && 
event->mimeData()->hasFormat(
"vp1/enabledphisectors"))
 
  464     event->acceptProposedAction();
 
  470   QByteArray 
data = 
event->mimeData()->data(
"vp1/enabledphisectors");
 
  471   event->acceptProposedAction();
 
  479     fitInView(scene()->sceneRect());
 
  502   if (
l.count()<2||
l.front().lower()!=0.0||
l.back().upper()!=(2*
M_PI))
 
  504   l.front().setLower(
l.back().lower()-(2*
M_PI));
 
  513      theclass->messageVerbose(
"enabledPhiRangesNoCache()");
 
  515   QList<VP1Interval> 
l;
 
  519   const unsigned int n = secstatus.count();
 
  521   const double dphi = (2*
M_PI)/
n;
 
  523     qDebug() << 
"n: " << 
n << 
" - dphi:" << dphi;
 
  529   for (
unsigned i = 0; 
i < 
n; ++
i) {
 
  530     const bool status = secstatus[
i];
 
  552     theclass->messageDebug(
"exiting enabledPhiRangesNoCache()...");
 
  568        messageDebug(
"Cache not valid. Checking for changes...");
 
  579      messageDebug(
"enabledPhiRanges(double phi_min,double phi_max)");
 
  582   if (phi_min>=phi_max)
 
  583     return QList<VP1Interval>();
 
  584   if (phi_max-phi_min>=(2*
M_PI))
 
  594   if (phi_max>(2*
M_PI)) {
 
  609   if (
l.front().lower()<0.0) {
 
  611     l.front().setLower(0.0);
 
  619   for ( 
int i = 0; 
i < 
l.count(); ) {
 
  622     if (b <= phi_min||a >= phi_max) {
 
  626     l[
i].setLower(phi_min);
 
  628     l[
i].setUpper(phi_max);
 
  653      theclass->messageDebug(
"checkForChanges()");
 
  659   QList<VP1Interval> 
r = enabledPhiRangesNoCache(sectorstatus,cachedAllOn, cachedAllOff);
 
  660   if (cachedRanges == 
r) {
 
  668     for(
int i=0;
i<
r.count();++
i)
 
  669     s+= 
r.at(
i).toString()+(
i==
r.count()-1?
"":
", ");
 
  670     theclass->messageVerbose(
"Emitting enabledPhiRangesChanged(" 
  671                  +theclass->enabledRangesToString()+
")");
 
  673   emit theclass->enabledPhiRangesChanged(
r);
 
  681   if (iSector<0||iSector>=nSectors||nSectors<1)
 
  691   const double dphi = (2*
M_PI)/nSectors;
 
  707     return QVector<bool>();
 
  708   QVector<bool> 
v(nSectors,
false);
 
  709   for (
int i = 0; 
i < nSectors; ++
i)
 
  723   int iphi = 
static_cast<int>(nSectors*
phi/((2*
M_PI)));
 
  731   QByteArray byteArray;
 
  732   QBuffer 
buffer(&byteArray);
 
  733   buffer.open(QIODevice::WriteOnly);
 
  754   buffer.open(QIODevice::ReadOnly);
 
  762   QVector<bool> restored_sectorstatus;
 
  763   state >> restored_sectorstatus;
 
  766   bool save = blockSignals(
true);
 
  794   if (oldEnabledRanges.isEmpty()) {
 
  798   if (oldEnabledRanges.count()==1&&oldEnabledRanges.first().length()>=2*
M_PI*(1.0-1.0e-10)) {
 
  802   const unsigned n = 
target.size();
 
  804   const double dphi = (2*
M_PI)/
n;
 
  806   for (
unsigned i = 0; 
i < 
n; ++
i) {
 
  808     for(
const VP1Interval& oldrange : oldEnabledRanges) {
 
  821   event->acceptProposedAction();
 
  838   if (allowedNSectors.isEmpty()) {
 
  844   for(
int s : allowedNSectors) {
 
  853   if (allowCustom&&!allowedNSectors.contains(
m_d->
sectorstatus.count())) {
 
  859   std::sort(allowedNSectors.begin(), allowedNSectors.end());
 
  875     messageDebug(
"check - sectorstatus.isEmpty? " + 
str(checkA + checkB) );